sqlplus 中直接敲入存儲過程代碼(create or replace procedure ...), / 結束,
成都創(chuàng)新互聯(lián)是一家集網(wǎng)站建設,察布查爾錫伯企業(yè)網(wǎng)站建設,察布查爾錫伯品牌網(wǎng)站建設,網(wǎng)站定制,察布查爾錫伯網(wǎng)站建設報價,網(wǎng)絡營銷,網(wǎng)絡優(yōu)化,察布查爾錫伯網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學習、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。
如果代碼沒有錯誤,該過程就被保存到數(shù)據(jù)庫中。
可以用 exec 過程名 運行。
如果是plsql developer之類的工具,那更簡單,編輯完存儲過程后,有運行按鈕,點擊即可。
服務器無法開機保存oracle數(shù)據(jù)的方法:
1、如果SQLdevelop可以連接數(shù)據(jù)庫,從新開一個賬號,分配表空間,進行數(shù)據(jù)庫復制,這是最簡單的方法。
2、如不能鏈接數(shù)據(jù)庫,可使用PLSQL進行遠程登錄oracle進行數(shù)據(jù)庫備份。
Oracle自動導入導出功能
導入用IMP命令
導出用EXP命令
可以將數(shù)據(jù)庫中所有元素(表、視圖、存儲過程、觸發(fā)器等)導出成一個
DMP
文件保存
是指sqlplus的查詢輸出格式?
這個沒多大用product\12.2.0\dbhome_1\sqlplus\admin 里面有個glogin.sql能改全局設定 但沒啥意義
oracle中執(zhí)行了insert、update、delete這三個DML語句后,結果在未提交前實際上是保存在undo空間內,只有提交之后,才會真正寫入到表中。所以會發(fā)生你的問題。
提交語句:commit
另外,在未做提交前,其他人是無法select到你處理的數(shù)據(jù)的,看到的是未處理前的數(shù)據(jù)。
還有一點要說明,當你執(zhí)行了update、delete時,語句所影響的數(shù)據(jù)會被oracle自動鎖定,其他人只能查,而不能update或delete,如果執(zhí)行update或delete,那么就會產(chǎn)生數(shù)據(jù)庫鎖。而鎖一旦產(chǎn)生,對系統(tǒng)的影響會很大,因此應盡快提交。
這個我其實也不大懂 不過以前在倉庫中存了這方面的一點小東東 希望對你游泳 嘿嘿 不知道是不是你想要的 先搞上來你看看吧
Oracle中的BLOB和CLOB
一、區(qū)別和定義
LONG: 可變長的字符串數(shù)據(jù),最長2G,LONG具有VARCHAR2列的特性,可以存儲長文本一個表中最多一個LONG列
LONG RAW: 可變長二進制數(shù)據(jù),最長2G
CLOB: 字符大對象Clob 用來存儲單字節(jié)的字符數(shù)據(jù)
NCLOB: 用來存儲多字節(jié)的字符數(shù)據(jù)
BLOB: 用于存儲二進制數(shù)據(jù)
BFILE: 存儲在文件中的二進制數(shù)據(jù),這個文件中的數(shù)據(jù)只能被只讀訪。但該文件不包含在數(shù)據(jù)庫內。
bfile字段實際的文件存儲在文件系統(tǒng)中,字段中存儲的是文件定位指針.bfile對oracle來說是只讀的,也不參與事務性控制和數(shù)據(jù)恢復.
CLOB,NCLOB,BLOB都是內部的LOB(Large Object)類型,最長4G,沒有LONG只能有一列的限制
要保存圖片、文本文件、Word文件各自最好用哪種數(shù)據(jù)類型?
--BLOB最好,LONG RAW也不錯,但Long是oracle將要廢棄的類型,因此建議用BLOB。
二、操作
1、 get
CLOB
java 代碼
//獲得數(shù)據(jù)庫連接
Connection con = ConnectionFactory.getConnection();
con.setAutoCommit(false);
Statement st = con.createStatement();
//不需要“for update”
ResultSet rs = st.executeQuery("select CLOBATTR from TESTCLOB where ID=1");
if (rs.next())
{
java.sql.Clob clob = rs.getClob("CLOBATTR");
Reader inStream = clob.getCharacterStream();
char[] c = new char[(int) clob.length()];
inStream.read(c);
//data是讀出并需要返回的數(shù)據(jù),類型是String
data = new String(c);
inStream.close();
}
inStream.close();
con.commit();
con.close();
BLOB
java 代碼
//獲得數(shù)據(jù)庫連接
Connection con = ConnectionFactory.getConnection();
con.setAutoCommit(false);
Statement st = con.createStatement();
//不需要“for update”
ResultSet rs = st.executeQuery("select BLOBATTR from TESTBLOB where ID=1");
if (rs.next())
{
java.sql.Blob blob = rs.getBlob("BLOBATTR");
InputStream inStream = blob.getBinaryStream();
//data是讀出并需要返回的數(shù)據(jù),類型是byte[]
data = new byte[input.available()];
inStream.read(data);
inStream.close();
}
inStream.close();
con.commit();
con.close();
2、 put
CLOB
java 代碼
//獲得數(shù)據(jù)庫連接
Connection con = ConnectionFactory.getConnection();
con.setAutoCommit(false);
Statement st = con.createStatement();
//插入一個空對象empty_clob()
st.executeUpdate("insert into TESTCLOB (ID, NAME, CLOBATTR) values (1, "thename", empty_clob())");
//鎖定數(shù)據(jù)行進行更新,注意“for update”語句
ResultSet rs = st.executeQuery("select CLOBATTR from TESTCLOB where ID=1 for update");
if (rs.next())
{
//得到java.sql.Clob對象后強制轉換為oracle.sql.CLOB
oracle.sql.CLOB clob = (oracle.sql.CLOB) rs.getClob("CLOBATTR");
Writer outStream = clob.getCharacterOutputStream();
//data是傳入的字符串,定義:String data
char[] c = data.toCharArray();
outStream.write(c, 0, c.length);
}
outStream.flush();
outStream.close();
con.commit();
con.close();
BLOB
java 代碼
//獲得數(shù)據(jù)庫連接
Connection con = ConnectionFactory.getConnection();
con.setAutoCommit(false);
Statement st = con.createStatement();
//插入一個空對象empty_blob()
st.executeUpdate("insert into TESTBLOB (ID, NAME, BLOBATTR) values (1, "thename", empty_blob())");
//鎖定數(shù)據(jù)行進行更新,注意“for update”語句
ResultSet rs = st.executeQuery("select BLOBATTR from TESTBLOB where ID=1 for update");
if (rs.next())
{
//得到java.sql.Blob對象后強制轉換為oracle.sql.BLOB
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob("BLOBATTR");
OutputStream outStream = blob.getBinaryOutputStream();
//data是傳入的byte數(shù)組,定義:byte[] data
outStream.write(data, 0, data.length);
}
outStream.flush();
outStream.close();
con.commit();
con.close();
=======================================================================
厚厚發(fā)表于 2006年06月27日
網(wǎng)絡上很多關于JAVA對Oracle中BLOB、CLOB類型字段的操作說明,有的不夠全面,有的不夠準確,甚至有的簡直就是胡說八道。最近的項目正巧用到了這方面的知識,在這里做個總結。
環(huán)境:
Database: Oracle 9i
App Server: BEA Weblogic 8.14
表結構:
CREATE TABLE TESTBLOB (ID Int, NAME Varchar2(20), BLOBATTR Blob)
CREATE TABLE TESTBLOB (ID Int, NAME Varchar2(20), CLOBATTR Clob)
JAVA可以通過JDBC,也可以通過JNDI訪問并操作數(shù)據(jù)庫,這兩種方式的具體操作存在著一些差異,由于通過App Server的數(shù)據(jù)庫連接池JNDI獲得的數(shù)據(jù)庫連接提供的java.sql.Blob和java.sql.Clob實現(xiàn)類與JDBC方式提供的不同,因此在入庫操作的時候需要分別對待;出庫操作沒有這種差異,因此不用單獨對待。
一、BLOB操作
1、入庫
(1)JDBC方式
//通過JDBC獲得數(shù)據(jù)庫連接
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:testdb", "test", "test");
con.setAutoCommit(false);
Statement st = con.createStatement();
//插入一個空對象empty_blob()
st.executeUpdate("insert into TESTBLOB (ID, NAME, BLOBATTR) values (1, "thename", empty_blob())");
//鎖定數(shù)據(jù)行進行更新,注意“for update”語句
ResultSet rs = st.executeQuery("select BLOBATTR from TESTBLOB where ID=1 for update");
if (rs.next())
{
//得到java.sql.Blob對象后強制轉換為oracle.sql.BLOB
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob("BLOBATTR");
OutputStream outStream = blob.getBinaryOutputStream();
//data是傳入的byte數(shù)組,定義:byte[] data
outStream.write(data, 0, data.length);
}
outStream.flush();
outStream.close();
con.commit();
con.close();
(2)JNDI方式
//通過JNDI獲得數(shù)據(jù)庫連接
Context context = new InitialContext();
ds = (DataSource) context.lookup("ORA_JNDI");
Connection con = ds.getConnection();
con.setAutoCommit(false);
Statement st = con.createStatement();
//插入一個空對象empty_blob()
st.executeUpdate("insert into TESTBLOB (ID, NAME, BLOBATTR) values (1, "thename", empty_blob())");
//鎖定數(shù)據(jù)行進行更新,注意“for update”語句
ResultSet rs = st.executeQuery("select BLOBATTR from TESTBLOB where ID=1 for update");
if (rs.next())
{
//得到java.sql.Blob對象后強制轉換為weblogic.jdbc.vendor.oracle.OracleThinBlob(不同的App Server對應的可能會不同)
weblogic.jdbc.vendor.oracle.OracleThinBlob blob = (weblogic.jdbc.vendor.oracle.OracleThinBlob) rs.getBlob("BLOBATTR");
OutputStream outStream = blob.getBinaryOutputStream();
//data是傳入的byte數(shù)組,定義:byte[] data
outStream.write(data, 0, data.length);
}
outStream.flush();
outStream.close();
con.commit();
con.close();
2、出庫
//獲得數(shù)據(jù)庫連接
Connection con = ConnectionFactory.getConnection();
con.setAutoCommit(false);
Statement st = con.createStatement();
//不需要“for update”
ResultSet rs = st.executeQuery("select BLOBATTR from TESTBLOB where ID=1");
if (rs.next())
{
java.sql.Blob blob = rs.getBlob("BLOBATTR");
InputStream inStream = blob.getBinaryStream();
//data是讀出并需要返回的數(shù)據(jù),類型是byte[]
data = new byte[input.available()];
inStream.read(data);
inStream.close();
}
inStream.close();
con.commit();
con.close();
二、CLOB操作
1、入庫
(1)JDBC方式
//通過JDBC獲得數(shù)據(jù)庫連接
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:testdb", "test", "test");
con.setAutoCommit(false);
Statement st = con.createStatement();
//插入一個空對象empty_clob()
st.executeUpdate("insert into TESTCLOB (ID, NAME, CLOBATTR) values (1, "thename", empty_clob())");
//鎖定數(shù)據(jù)行進行更新,注意“for update”語句
ResultSet rs = st.executeQuery("select CLOBATTR from TESTCLOB where ID=1 for update");
if (rs.next())
{
//得到java.sql.Clob對象后強制轉換為oracle.sql.CLOB
oracle.sql.CLOB clob = (oracle.sql.CLOB) rs.getClob("CLOBATTR");
Writer outStream = clob.getCharacterOutputStream();
//data是傳入的字符串,定義:String data
char[] c = data.toCharArray();
outStream.write(c, 0, c.length);
}
outStream.flush();
outStream.close();
con.commit();
con.close();
(2)JNDI方式
//通過JNDI獲得數(shù)據(jù)庫連接
Context context = new InitialContext();
ds = (DataSource) context.lookup("ORA_JNDI");
Connection con = ds.getConnection();
con.setAutoCommit(false);
Statement st = con.createStatement();
//插入一個空對象empty_clob()
st.executeUpdate("insert into TESTCLOB (ID, NAME, CLOBATTR) values (1, "thename", empty_clob())");
//鎖定數(shù)據(jù)行進行更新,注意“for update”語句
ResultSet rs = st.executeQuery("select CLOBATTR from TESTCLOB where ID=1 for update");
if (rs.next())
{
//得到java.sql.Clob對象后強制轉換為weblogic.jdbc.vendor.oracle.OracleThinClob(不同的App Server對應的可能會不同)
weblogic.jdbc.vendor.oracle.OracleThinClob clob = (weblogic.jdbc.vendor.oracle.OracleThinClob) rs.getClob("CLOBATTR");
Writer outStream = clob.getCharacterOutputStream();
//data是傳入的字符串,定義:String data
char[] c = data.toCharArray();
outStream.write(c, 0, c.length);
}
outStream.flush();
outStream.close();
con.commit();
con.close();
2、出庫
//獲得數(shù)據(jù)庫連接
Connection con = ConnectionFactory.getConnection();
con.setAutoCommit(false);
Statement st = con.createStatement();
//不需要“for update”
ResultSet rs = st.executeQuery("select CLOBATTR from TESTCLOB where ID=1");
if (rs.next())
{
java.sql.Clob clob = rs.getClob("CLOBATTR");
Reader inStream = clob.getCharacterStream();
char[] c = new char[(int) clob.length()];
inStream.read(c);
//data是讀出并需要返回的數(shù)據(jù),類型是String
data = new String(c);
inStream.close();
}
inStream.close();
con.commit();
con.close();
需要注意的地方:
1、java.sql.Blob、oracle.sql.BLOB、weblogic.jdbc.vendor.oracle.OracleThinBlob幾種類型的區(qū)別
2、java.sql.Clob、oracle.sql.CLOB、weblogic.jdbc.vendor.oracle.OracleThinClob幾種類型的區(qū)別
網(wǎng)站名稱:oracle如何保存型號,oracle存文件用什么格式
當前路徑:http://aaarwkj.com/article24/dssihje.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供、動態(tài)網(wǎng)站、軟件開發(fā)、網(wǎng)站策劃、網(wǎng)頁設計公司、微信小程序
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)