patternMinor
Inserting data into a table with one value as clob and blob
Viewed 0 times
withintoandvaluebloboneclobinsertingdatatable
Problem
My table has one clob column and one blob column. I need to insert data into it through insert statements.
The length of data to be inserted is more than 4000 chars.
When I do export of insert statements is sql navigator I get empty values.
I also tried to do insert it data like this.I have added only example data to be inserted.The actual data to be inserted is large.
Can some one tell me best way to insert data into table in these scenario.
Or anyway to do export and import this data will also help.
The length of data to be inserted is more than 4000 chars.
When I do export of insert statements is sql navigator I get empty values.
INSERT INTO mytable VALUES('REQUEST',EMPTY_CLOB(),EMPTY_BLOB());I also tried to do insert it data like this.I have added only example data to be inserted.The actual data to be inserted is large.
INSERT INTO mytable VALUES('REQUEST2','{"customer"asxcbasjbab....:}',NULL);Can some one tell me best way to insert data into table in these scenario.
Or anyway to do export and import this data will also help.
Solution
In SQL, the limit is 4,000 characters. Using straight SQL like that, without a bind
variable, you'll be limited to 4,000 characters.
Steps to insert lob values :
-
1) Create a table and name it TBL_CLOB with 2 fields:
id_int = integer;
clob_txt =clob;
-
2) Create a stored procedure and name it P_CLOB with the following
code:
(P_ID_INT in int,P_CLOB_TXT in varchar2)as
begin
insert into TBL_CLOB values(P_ID_INT,P_CLOB_TXT);
end;
the CLOB field:
SQL> exec p_clob(1,rpad('',32000,''));
SQL> commit;
SQL> exec p_clob(2,rpad('',19872,''));
SQL> commit;
characters in the CLOB fields:
SQL> select id_int,dbms_lob.getlength(clob_txt) from tbl_clob;
ID_INT DBMS_LOB.GETLENGTH(CLOB_TXT)
---------- ----------------------------
1 32000
2 19872
Makes sense ?
variable, you'll be limited to 4,000 characters.
Steps to insert lob values :
-
1) Create a table and name it TBL_CLOB with 2 fields:
id_int = integer;
clob_txt =clob;
-
2) Create a stored procedure and name it P_CLOB with the following
code:
(P_ID_INT in int,P_CLOB_TXT in varchar2)as
begin
insert into TBL_CLOB values(P_ID_INT,P_CLOB_TXT);
end;
- 3) Test inserting up to 32000. Use SQL Plus and enter some starts in
the CLOB field:
SQL> exec p_clob(1,rpad('',32000,''));
SQL> commit;
SQL> exec p_clob(2,rpad('',19872,''));
SQL> commit;
- 4) Retrieve the 2 records you just inserted and count the number of
characters in the CLOB fields:
SQL> select id_int,dbms_lob.getlength(clob_txt) from tbl_clob;
- 5) You should get something like this:
ID_INT DBMS_LOB.GETLENGTH(CLOB_TXT)
---------- ----------------------------
1 32000
2 19872
Makes sense ?
Context
StackExchange Database Administrators Q#61046, answer score: 3
Revisions (0)
No revisions yet.