Operation of the CLOB Type field in Oracle

xiaoxiao2021-03-06  20

Here's this article is very detailed, I will do two points to add: First, LOB data cannot be directly inserted as other types of data (INSERT). An empty LOB object must be inserted before insertion, and the CLOB type empty object is EMPTY_CLOB (), the blob type empty object is EMPTY_BLOB (). Then the select command query gets the previously inserted record and locks, followed by modifying the empty object to the LOB object to be inserted. Second, inserted into the update, be sure to set it to false. Otherwise, if you look up again, you cannot update it correctly. When you look up, you must use the select xxx from table where id = 'xxx' for update if not Update will Newspaper: "Row Containing The Lob Value IS Not Locked"; if it is not automatically submitted to false, "Fetch out of sequence" will be reported to False. It is noted that the above two points can generally be inserted into the Clob type field. -------------------------------------------------- -------------------------------------------------- ----- The following code and text are the articles of someone else online, and then thank you for the original author. -------------------------------------------------- -------------------------------------------------- ------ Recently in J2EE projects need to use the LOB field to save text information and images, to the online search, there are still a lot, take a closer look, but not very all, there is also a mistake, After a few days of practice, the problem is solved, and the way, I hope to be aware of the friends you need.

There are two main CLOBs and BLOBs we use in LOB, we discuss two types

1.Clob is a characteristic LOB, mainly stores text information, the longest

4G

In the J2EE program, the character information in the textarea in the web page is relatively long. When the VARCHAR2 field type cannot be satisfied, we have to use the Clob data type, and our project will encounter this situation. Now let's talk How to access a Clob field

Now I want to save the information of the textarea element in the web page into the clob field of the database, we all know that the information in the textarea must certainly be saved into clob, we get the String type in the background. Related information about Oracle fields You can check the Oracle Technology Network. Some of the descriptions of types related to blob.clob are extracted below. It is convenient for everyone's understanding. Field Type: BLOB, Clob, NClob Description: Three large objects (LOB), used to save large graphics files or format text files, such as Miceosoft Word documents, and audio, video, etc. non-text files, the maximum length is 4GB. There are several types of LOB depends on the type of the byte you use, and Oracle 8i is actually stored in the database inside the database. Special operations such as read, storage, write, etc. can be performed.

The attribute we operate is (character ID, Clob type picstr), and we now assume that a large character object STR already contains data we need to store the PICSTR field. And the Connection object CONN has been established. The following example programs are also not written by throwing exceptions because they don't want to take up too much space. Let's refer to the API DOC. You can know what abnormally throws, just tell you how to write.

Code: (1) Insert operation of database CLOB type ******************************************************** *********** java.sql.preparedStatement PSTMT = NULL; ResultSet RS = NULL; STRING Query = ""; conn.setautocommit (false); query = "Insert Into Clobtest_Table (ID, PICSTR) VALUES (?, empty_clob ()) "; java.sql.PreparedStatement pstmt = conn.prepareStatement (query); pstmt.setString (1," 001 "); pstmt.executeUpdate (); pstmt = null query =" select picstr from clobtest_table WHERE ID = '001' for update "; pstmt = con.preparestatement (query) = pstmt.executeQuery (); oracle.sql.clob clobtt = null; if (rs.next ()) {Clobtt = (Oracle.sql .Clob) gtClob (1);} WRITER WR = Clobtt.getCharacterOutputStream (); wr.write (); wr.flush (); wr.close (); rs.close (); con enride () (2) Whether the database has been successfully inserted into the database ******************************************** ************* PL / SQL package dBMS_LOB to process LOB data. Check if the insertion of the initial insert is successful. Use the GetLength this procedure with the DBMS_LOB package to detect if the STR has been stored in the PICSTR field. Such as: SQL> SELECT DBMS_LOB.GETLENGTH (PICSTR) from clobtest_table; (3) Perform reading operations for database CLOB type ************************ *********************** is very simple to read relative inserts. Basic steps and half of the database data is not too big.

转载请注明原文地址:https://www.9cbs.com/read-61120.html

New Post(0)