The Oracle Database inserts a string into a BLOB field and converts the inserted BLOB data into a string display method.

Source: Internet
Author: User


The Oracle Database inserts a string into a BLOB field and converts the inserted BLOB data into a string display method.


First, create a table create table TB_TEST (id number, blb blob) in the database, and insert an empty data insert into tb_test (id, blb) values (1, empty_blob () Finally changes the BLOB field value declare ctions BLOB; amount BINARY_INTEGER; offset INTEGER; first_direction VARCHAR2 (100); more_directions VARCHAR2 (500); begin update set blb = empty_blob () where id = 1; -- set the BLOB field to EMPTY_BLOB () select blb into directions from tb_test where id = 1 for up for updates. Date; -- be sure to use for update to lock the record. Otherwise, DBMS_LOB.OPEN will encounter an error DBMS_LOB.OPEN (directions, DBMS_LOB.LOB_READWRITE); first_direction: = 'This is my first data to insert blob, test how it works and whether pl/SQL can be directly inserted into the inserted data value! '; Amount: = LENGTHB (first_direction); -- number of characters to write -- if there is a Chinese character, LENGTHB offset: = 1; -- begin writing to the first character of the CLOB DBMS_LOB.WRITE (directions, amount, offset, limit (first_direction); -- the explain function converts the string to the binary number DBMS_LOB.CLOSE (directions); commit; end; convert the inserted BLOB data to the string display mode: select id, UTL_RAW.cast_to_varchar2 (blb) blb from tb_test t; this mode displays plain text characters The string is displayed normally, when the data I inserted is <form id = "form1" name = "form1"> <input type = "data" value = "hello"> </form> the query is displayed as null.

Author sqcjy111

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.