oracle| string
1, in the database to build a new table for testing.
CREATE Tbale Tb_test
(
ID number,
BLB BLOB
);
COMMIT;
2. Insert a new record into the Tb_test table for testing.
INSERT into Tb_test VALUES (1, Empty_blob ());
COMMIT;
NOTE: Insert a new record into a data table with a BLOB type field, and you cannot fill in the value directly, you must first insert a empty_blob () into the Blob field, and then use Dbms_lob. The Write function writes the value of a blob.
3, write the following string to the BLB field of the record with ID 1: ' Follow I-75 across the Mackinac Bridge. Hello! ';
Declare
Directions BLOB;
Amount Binary_integer;
Offset INTEGER;
First_direction VARCHAR2 (100);
More_directions VARCHAR2 (500);
Begin
Update tb_test Set blb = Empty_blob () where id = 1; --Update and new to set the BLOB field to Empty_blob ()
Select BLB into directions from tb_test where id = 1 for update; --Be sure to lock the record with the for update otherwise
--dbms_lob. Open will be wrong
Dbms_lob. OPEN (directions, Dbms_lob. Lob_readwrite);
First_direction: = ' Follow I-75 across the Mackinac Bridge. Hello! ';
Amount: = LENGTHB (first_direction); --number of characters to write
--Chinese must use LENGTHB
Offset: = 1; --begin writing to the The CLOB
Dbms_lob. WRITE (directions, amount, offset, Utl_raw.cast_to_raw (first_direction));
The--utl_raw.cast_to_raw function converts a string into a binary number
Dbms_lob. Close (directions);
Commit
End