Trying to read a CLOB column
Hi everybody!
My first post over here is to send you up a problem that I have on my code.
I'm trying to put on a variable some HTML codes and (in the middle) a CLOB text for a newsletter... so here is the code:
<BR><BR>
$var1 = " SELECT P.CODNOTICIA, P.TITULO, P.TEXTO, P.TEXTO2, TO_CHAR(P.DATA,'DD/MM/YYYY') DATA ";<BR>
$var1 .= " FROM ALDEIA.NEWSLETTER_NOTICIA_PORTAL P ";<BR>
$var1 .= " WHERE P.CODNOTICIA IN (" . openarray($codigos) . ") "; <BR>
$var1 .= " ORDER BY 5 ";<BR>
$rsNoticia = ociparse($DBConn,$var1);<BR>
ociexecute($rsNoticia);
<BR><BR>
$texto = ociresult($rsNoticia, "TEXTO");
$temp .= " " . nl2br($texto) . "< br >" . chr(10) . chr(13);<BR>
<BR><BR>
The output of this simply does not return anything.<BR>
If someone can help, I wuld be verry appreciate.<BR>
It doesn't look like you're outputting it here (just in case it was actually that easy :)).
You should be checking the return codes from your OCI calls. This wasn't actually run, so there may be some syntax errors... but you get the idea :)
$rsNoticia = ociparse($DBConn,$var1);
if (!$rsNoticia)
$e = oci_error($DBConn);
echo htmlentities($e['message']);
die();
if (!ociexecute($rsNoticia))
$e = oci_error($rsNoticia);
echo htmlentities($e['message']);
echo "<pre>";
echo htmlentities($e['sqltext']);
printf("\n%".($e['offset']+1)."s", "^");
echo "</pre>";
die();
$texto = ociresult($rsNoticia, "TEXTO");
if (!$texto)
$e = oci_error($rsNoticia);
echo htmlentities($e['message']);
die();
$temp .= " " . nl2br($texto) . "< br >" . chr(10) . chr(13);
echo $temp;
Similar Messages
-
Data updated by another user when trying to update a CLOB column value
I just recently upgraded to version 1.2.1 (Build MAIN-32.13), and since I have, I am now getting this message when editing the text within a CLOB column of a table:
Data you attempted to update was updated by another user. You will have to rollback and refresh the table. Rollback now?
I am confident that no one else is in the table, as I am the only one connected to this DB right now. Also, I have shut down SQL Developer completely and restarted it. Again, I get the same error.
Also, the CLOB is less than 2500 characters, so it's not a limitation with the 4k chars.
I really can't update it easily via SQL because there is formatting in the text (carriage
returns, etc).
Any ideas? Any workarounds?
Thanks,
-VikkiOK. A few things I've noticed as I've played with it more.
1 - It does not happen on EVERY update to a CLOB. (Some save successfully.)
2 - Once I get it on a CLOB, it seems to happen then on every subsequent CLOB.
3 - It's not just one table -- several tables do it.
4 - It's not even just updating CLOB columns -- I just had it happen on a varchar2 column where there is also a CLOB in the table.
Thank you for the instructions on how to see the debug console. Here is what I got as an exception (and sorry for the line wrapping):
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.S
tring
at oracle.dbtools.raptor.controls.celleditor.ResultSetCellEditor$1.actio
nPerformed(ResultSetCellEditor.java:140)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:18
49)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
a:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.S
tring
at oracle.dbtools.raptor.controls.celleditor.ResultSetCellEditor$1.actio
nPerformed(ResultSetCellEditor.java:140)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:18
49)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
a:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
reloadBuffers(): 56 nodes checked in 0.001488707 second(s)
reloadBuffers(): 56 nodes checked in 0.001101633 second(s)
reloadBuffers(): 56 nodes checked in 8.70581E-4 second(s)
reloadBuffers(): 56 nodes checked in 0.00159078 second(s) -
Reading a CLOB Column with ODBC
When I do a "select colCLOB from Table1", it is truncating the data. It looks like after about 1000 chars(+/-), it puts a bunch of spaces in. I am on 8.1.6. If I use OleDB it works fine. Any Ideas? Thanks!
Here's Note:115946.1 from our support archives "Using ADO Stream Object and ODBC to Store and Retrieve Blobs in Oracle from VB". This may help you out.
'In order to use this sample, you must have a table created as follows:
' Name: LOB_TABLE
' COL: FIELD2 VARCHAR2(50)
' COL: BLOBFIELD BLOB
'You must have references set to ADO 2.5 and Oracle's ODBC Driver 8.1.6
'Create a standard exe project
' Open a new form
' Put two command buttons on it
' Button #1: cmdSaveToFile
' Button #2: cmdSaveToDB
' Put the appropriate code in each routine.
'Modify connection information for your environment
' This has been tested using VB 6.0 SP4, Oracle 8.1.6 DB, and Oracle's 8.1.6 ODBC Driver
Option Explicit
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim mStream As ADODB.Stream
Dim ConnStr As String
Private Sub cmdSaveToFile_Click()
Screen.MousePointer = vbHourglass
Set cn = New ADODB.Connection
ConnStr = "UID=scott;PWD=tiger;DSN=ora816;"
Set cn = New ADODB.Connection
With cn
.ConnectionString = ConnStr
.Open
End With
' Open OLEDB connection
' cn.Provider = "OraOLEDB.Oracle"
' cn.ConnectionString = "Data Source=ora816;" & "User ID=scott;Password=tiger;"
' cn.Open
Set rs = New ADODB.Recordset
rs.Open "Select * from LOB_TABLE where FIELD2 IS NOT NULL", cn, adOpenKeyset, adLockOptimistic
' Create ADO stream object
Set mStream = New ADODB.Stream
' Set it to a binary file type
mStream.Type = adTypeBinary
' Open it
mStream.Open
' This writes the image from the blob field to the buffer
mStream.Write rs.Fields("BLOBFIELD1").Value
' This saves the stream to the file on disk
mStream.SaveToFile "C:\" & rs.Fields("FIELD2").Value
mStream.Close
Set mStream = Nothing
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
Screen.MousePointer = vbDefault
End Sub
Private Sub cmdSaveToDB_Click()
Screen.MousePointer = vbHourglass
Set cn = New ADODB.Connection
ConnStr = "UID=scott;PWD=tiger;DSN=ora816;"
Set cn = New ADODB.Connection
With cn
.ConnectionString = ConnStr
.Open
End With
' cn.Provider = "OraOLEDB.Oracle"
' cn.ConnectionString = "Data Source=ora816;" & "User ID=scott;Password=tiger;"
' cn.Open
Set rs = New ADODB.Recordset
rs.Open "Select * from LOB_TABLE", cn, adOpenKeyset, adLockOptimistic
' Create the ADO Stream object
Set mStream = New ADODB.Stream
' Make it a binary type
mStream.Type = adTypeBinary
' Open the stream
mStream.Open
' Read the file into the stream buffer
mStream.LoadFromFile "c:\documents and settings\rlosey\My Documents\My Pictures\DCP_1305.jpg"
' Add the blob to the database
With rs
.AddNew
.Fields("BLOBFIELD1").Value = mStream.Read
.Fields("FIELD2").Value = "DCP_1305.jpg"
.Update
End With
mStream.Close
Set mStream = Nothing
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
Screen.MousePointer = vbDefault
End Sub
null -
Read CLOB column - piece-wise break-up
I have two tables File_Master and File_Detail
File_Master Primary key FILE_ID
File_Detail Primary key FILE_ID,LINE_ID
I have a CLOB column FILE_CONTENT in table File_Master.
For every FILE_ID record in File_Master, several hundreds of lines are stored in the CLOB column.
I want to read this CLOB column 'File_Content' and and break every line (1000 Characters)
piecewise to populate columns of File_Detail.
Since there will be thousands of lines to process, what would be the best approach in writing PL/SQL code for better performance?
Thanks in advance.Do you want actual lines (terminated by a Unix or DOS linefeed) from the CLOB?
I use the following function for processing lines from CLOBs (and then further tokenising and parsing each line):
create or replace type TStrings is table of varchar2(4000);
create or replace function ClobToLines( c clob, lineTerminator varchar2 default null ) return TStrings pipelined is
-- function: CLOB TO LINES
-- descr: reads lines from a clob and returns each line as a separate row
pos integer;
line varchar2(4000);
offset integer := 1;
charSep varchar2(10);
amount integer := 1;
begin
-- if no CRLF specified, detect whether DOS or Unix linefeeds are used
if lineTerminator is null then
pos := DBMS_LOB.InStr( c, chr(10), offset, 1 );
if pos = 0 then
raise_application_error(
-20001,
'The CLOB does not contain char #10 (used by both DOS and Unix linefeeds) and failed to parse.'
end if;
if pos > 1 then
DBMS_LOB.Read(
lob_loc => c,
amount => amount,
offset => pos-1,
buffer => charSep
end if;
if charSep = chr(13) then
charSep := chr(13)||chr(10);
else
charSep := chr(10);
end if;
else
charSep := lineTerminator;
end if;
while (offset < DBMS_LOB.GetLength(c) ) loop
pos := DBMS_LOB.InStr( c, charSep, offset, 1 );
if pos > 0 then
line := DBMS_LOB.SubStr( c, pos-offset, offset );
offset := pos + length(charSep);
else
offset := DBMS_LOB.GetLength( c ) + 1;
line := null;
end if;
pipe row( line );
end loop;
return;
end;
/ -
Limitation for CLOB columns? - ORA-01704: string literal too long
Hello!
I'm trying to update a CLOB column with more than 35000 characteres, but I get "ORA-01704: string literal too long".
The code:
declare
l_clob clob;
begin
update test set test = empty_clob()
WHERE ID = 1
returning test into l_clob;
dbms_lob.write( l_clob, length('A...here 35000xA...A'), 1,'A...here 35000xA...A');
end;
Is there any limitation for CLOB columns?
Thanks for help.
Danieluser605489 wrote:
32768 characteres :)Actually it's 1 character less than 32K...
*32767*
SQL> declare
2 v_vc varchar2(32768);
3 begin
4 null;
5 end;
6 /
v_vc varchar2(32768);
ERROR at line 2:
ORA-06550: line 2, column 17:
PLS-00215: String length constraints must be in range (1 .. 32767)
SQL>I guess it comes from a legacy thing where signed words (2 bytes) are/were used to represent a value. As the most significant bit of the word is used to represent the sign of the number the range goes from -32768 to 32767. -
How to Update a clob column..it gives error string literal too long
I am trying to update a clob column of a table but it gives error string literal too long plz tell me what's the issue
ORA-01704: string literal too longPeeyush wrote:
I am trying to update a clob column of a table but it gives error string literal too long plz tell me what's the issue
ORA-01704: string literal too longThere's a problem with my car. It won't start. Why won't it start? Please tell me!
Oh wait, you can't, because I haven't given you nearly enough information...
In other words, if you would like help in trying to work out where you've gone wrong, you should provide a small enough example of your code that demonstrates the error. We might then actually stand a chance of being able to help you! -
Hello All,
I am trying to query a CLOB column with some text string. Can anyone tell me how to do this. Here is a simple example of my code and the error message I get....
SQL> select title_column from atlas_table where clob_column like '%a%';
select title_column from atlas_table where clob_column like '%e%'
ERROR at line 1:
ORA-00932: inconsistent datatypes
Thanks,
DannySelecting a LOB from a table actually returns the LOB's locator and not the entire LOB value..
and you should have a frontend to retrieve the clob or blob..
if u have you can view/update/..do DML operations on the column
null -
How to read/write .CSV file into CLOB column in a table of Oracle 10g
I have a requirement which is nothing but a table has two column
create table emp_data (empid number, report clob)
Here REPORT column is CLOB data type which used to load the data from the .csv file.
The requirement here is
1) How to load data from .CSV file into CLOB column along with empid using DBMS_lob utility
2) How to read report columns which should return all the columns present in the .CSV file (dynamically because every csv file may have different number of columns) along with the primariy key empid).
eg: empid report_field1 report_field2
1 x y
Any help would be appreciated.If I understand you right, you want each row in your table to contain an emp_id and the complete text of a multi-record .csv file.
It's not clear how you relate emp_id to the appropriate file to be read. Is the emp_id stored in the csv file?
To read the file, you can use functions from [UTL_FILE|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm#BABGGEDF] (as long as the file is in a directory accessible to the Oracle server):
declare
lt_report_clob CLOB;
l_max_line_length integer := 1024; -- set as high as the longest line in your file
l_infile UTL_FILE.file_type;
l_buffer varchar2(1024);
l_emp_id report_table.emp_id%type := 123; -- not clear where emp_id comes from
l_filename varchar2(200) := 'my_file_name.csv'; -- get this from somewhere
begin
-- open the file; we assume an Oracle directory has already been created
l_infile := utl_file.fopen('CSV_DIRECTORY', l_filename, 'r', l_max_line_length);
-- initialise the empty clob
dbms_lob.createtemporary(lt_report_clob, TRUE, DBMS_LOB.session);
loop
begin
utl_file.get_line(l_infile, l_buffer);
dbms_lob.append(lt_report_clob, l_buffer);
exception
when no_data_found then
exit;
end;
end loop;
insert into report_table (emp_id, report)
values (l_emp_id, lt_report_clob);
-- free the temporary lob
dbms_lob.freetemporary(lt_report_clob);
-- close the file
UTL_FILE.fclose(l_infile);
end;This simple line-by-line approach is easy to understand, and gives you an opportunity (if you want) to take each line in the file and transform it (for example, you could transform it into a nested table, or into XML). However it can be rather slow if there are many records in the csv file - the lob_append operation is not particularly efficient. I was able to improve the efficiency by caching the lines in a VARCHAR2 up to a maximum cache size, and only then appending to the LOB - see [three posts on my blog|http://preferisco.blogspot.com/search/label/lob].
There is at least one other possibility:
- you could use [DBMS_LOB.loadclobfromfile|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_lob.htm#i998978]. I've not tried this before myself, but I think the procedure is described [here in the 9i docs|http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96591/adl12bfl.htm#879711]. This is likely to be faster than UTL_FILE (because it is all happening in the underlying DBMS_LOB package, possibly in a native way).
That's all for now. I haven't yet answered your question on how to report data back out of the CLOB. I would like to know how you associate employees with files; what happens if there is > 1 file per employee, etc.
HTH
Regards Nigel
Edited by: nthomas on Mar 2, 2009 11:22 AM - don't forget to fclose the file... -
Error when trying to use (GUI Wizards) on Table with BLOB, CLOB columns.
I enjoyed watching the demo of ODP.NET/VS 2005 Environment where you can just drag the new command builders, data sets, etc.. but when I try this with a table that contains a BLOB and CLOB column it returns an error and basically cannot build the SQL needed to process these field types.
I would assume it could do this natively since it is somewhat of a primitive type. I also tried to point it to a Stored Proc that returned a blob and it caused an error when building the SQL.
So it appears it is not possible to use the GUI data access wizards for these column types. I can use them in code with the ODP.NET with no problems but it would be nice to be able to utilize the GUI Command Builders, etc...blob and clob are not supported i guess. oracle is a bit sluggish when it comes to VS and MS products!
-
ORA-01461 when trying to insert text 4000 characters into a CLOB column
I work on a Windows application that connects to databases using ODBC. I'm currently working on adding Oracle support to the application, but I'm running into a lot of problems inserting strings of more than 4000 characters into CLOB columns. First, I tried to do that directly using code similar to the following (setup, cleanup, and error checking snipped for clarity).
SQLHDBC hDbc;
SQLHSTMT hStmt;
unsigned char query[200];
SQLAllocStmt(hDbc, &hStmt);
strcpy(query,"INSERT INTO test_table (col_clob, col_int) ('long string', 1)");
SQLExecDirect(hStmt,query,strlen(query));
Of course, "long string" was really a string of more than 4000 characters. When I did that, I got an error indicating that I needed to use bind parameters for strings that long. However, bind parameters don't seem to work either. I changed my code to something like the following:
SQLHDBC hDbc;
SQLHSTMT hStmt;
unsigned char query[200];
+unsigned char *str=NULL;+
int str_size;
SQLAllocStmt(hDbc, &hStmt);
strcpy(query,"INSERT INTO test_table (col_clob, col_int) (:strvar, 1)");
SQLPrepare(hStmt,query,SQL_NTS);
str = (unsigned char*)malloc(6000 * sizeof(unsigned char));
SQLBindParameter(hStmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARBINARY, 0, 0, str, sizeof(str), &str_size);
strcpy(str,'long_string');
str_size = SQL_NTS;
SQLExecute(hStmt);
This code works fine when 'long_string' is less than 4000 characters. When it's greater than that, I get the following error:
+[Oracle][ODBC][Ora]ORA-01461: can bind a LONG value only for insert into a LONG column+
I'm using Visual Studio.NET 2003 on Windows XP, and Oracle client 11.1.0.6.0. My server version is as follows:
SQL> select * from v$version;
BANNER
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
I thought I read somewhere that this is a known bug with Oracle 10.2.0.1.0, but I can't seem to find the reference now. Can anyone confirm this or provide some assistance with this problem? Frankly, it seems kind of ridiculous that I can't do something as simple as inserting a reasonably sized amount of text into a CLOB column. I'm considering using BFILEs instead, but that would be kind of a pain to fit into our application, so I'd prefer not to do this if at all possible.
Thanks in advance for any help.I found this link referring to a similar problem that was apparently fixed in version 10.2.0.4 of the server: ORA-01461: can bind a LONG value only for insert into a LONG column Should I try to upgrade the server and see if that fixes things?
-
Error reading data from CLOB column into VARCHAR2 variable
Hi all,
Am hitting an issue retrieving data > 8K (minus 1) stored in a CLOB column into a VARCHAR2 variable in PL/SQL...
The "problem to be solved" here is storing DDL, in this case a "CREATE VIEW" statement, that is longer than 8K for later retrieval (and execution) using dynamic SQL. Given that the EXECUTE IMMEDIATE statement can take a VARCHAR2 variable (up to 32K(-1)), this should suffice for our needs, however, it seems that somewhere in the process of converting this VARCHAR2 text to a CLOB for storage, and then retrieving the CLOB and attempting to put it back into a VARCHAR2 variable, it is throwing a standard ORA-06502 exception ("PL/SQL: numeric or value error"). Consider the following code:
set serveroutput on
drop table test1;
create table test1(col1 CLOB);
declare
cursor c1 is select col1 from test1;
myvar VARCHAR2(32000);
begin
myvar := '';
for i in 1..8192 loop
myvar := myvar || 'a';
end loop;
INSERT INTO test1 (col1) VALUES (myvar);
for arec in c1 loop
begin
myvar := arec.col1;
dbms_output.put_line('Read data of length ' || length(myvar));
exception when others then
dbms_output.put_line('Error reading data: ' || sqlerrm);
end;
end loop;
end;
If you change the loop upper bound to 8191, all works fine. I'm guessing this might have something to do with the database character set -- we've recently converted our databases over to UTF-8, for Internationalizion support, and that seems to have changed underlying assumptions regarding character processing...?
As far as the dynamic SQL issue goes, we can probably use the DBMS_SQL interface instead, with it's EXECUTE procedure that takes a PL/SQL array of varchar2(32K) - the only issue there is reading the data from the CLOB column, and then breaking that data into an array but that doesn't seem insurmountable. But this same basic issue (when a 9K text block, let's say, turns into a >32K block after being CLOBberred) seems to comes up in other text-processing situations also, so any ideas for how to resolve would be much appreciated.
Thanks for any tips/hints/ideas...
JimFor those curious about this, here's the word from Oracle support (courtesy of Metalinks):
RESEARCH
========
Test the issue for different DB version and different characterset.
--Testing the following PL/SQL blocks by using direct assignment method(myvar := arec.col1;) on
different database version and different characterset.
SQL>create table test1(col1 CLOB);
--Inserting four CLOB data into test1.
declare
myvar VARCHAR2(32767);
begin
myvar := RPAD('a',4000);
INSERT INTO test1 (col1) VALUES (myvar);
myvar := RPAD('a',8191);
INSERT INTO test1 (col1) VALUES (myvar);
myvar := RPAD('b',8192);
INSERT INTO test1 (col1) VALUES (myvar);
myvar := RPAD('c',32767);
INSERT INTO test1 (col1) VALUES (myvar);
commit;
end;
--Testing the direct assignment method.
declare
cursor c1 is select col1, length(col1) len1 from test1;
myvar VARCHAR2(32767);
begin
for arec in c1 loop
myvar := arec.col1;
--DBMS_LOB.READ(arec.col1, arec.len1, 1, myvar);
dbms_output.put_line('Read data of length: ' || length(myvar));
end loop;
end;
The following are the summary of the test results:
===================================
1. If the database characterset is WE8ISO8859P1, then the above direct assignment
method(myvar := arec.col1;) works for database version 9i/10g/11g without any
errors.
2. If the database characterset is UTF8 or AL32UTF8, then the above direct assignment method(myvar := arec.col1;) will generate the "ORA-06502:
PL/SQL: numeric or value error" when the length of the CLOB data is greater
than 8191(=8K-1). The same error can be reproduced across all database versions
9i/10g/11g.
3. Using DBMS_LOB.READ(arec.col1, arec.len1, 1, myvar) method to read CLOB data into a VARCHAR2 variable works for both WE8ISO8859P1 and UTF8
characterset and for all database versions.
So - it seems as I'd surmised, UTF8 changes the way VARCHAR2 and CLOB data is handled. Not too surprising, I suppose - may you all be lucky enough to be able to stay away from this sort of issue. But - the DBMS_LOB.READ workaround is certainly sufficient for the text processing situations we find ourselves in currently.
Cheers,
Jim C. -
Trying to Insert an XML Element into XML data stored in CLOB column
Hi all,
My ORACLE DB version is:
('Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production');
('PL/SQL Release 11.2.0.2.0 - Production');
('CORE 11.2.0.2.0 Production');
('TNS for Linux: Version 11.2.0.2.0 - Production');
('NLSRTL Version 11.2.0.2.0 - Production');
I have this XML data stored in a CLOB column:
<Activity>
<Changes>
</Changes>
<Inserts>
</Inserts>
<Definition>
</Definition>
<Assignment TYPE="Apply">
</Assignment>
<Spawned>
<Activity>576D8CD9-57A1-8608-1563-8F6DC74BDF3C</Activity>
<Activity>11226E79-5D24-02EB-A950-D34A9CCFB3FF</Activity>
<Activity>DAA68DC0-CA9A-BB15-DE31-9596E19513EE</Activity>
<Activity>93F667D6-966A-7EAD-9B70-630D9BEFDDD2</Activity>
<Activity>FA63D9D3-86BB-3FF0-BE69-17EAA7581637</Activity>
</Spawned>
<SpawnedBy>AFC49BD4-5AA7-38C0-AE27-F59D16EE1B1C</SpawnedBy>
</Activity>
I am in need of some assistance in creating an update that will insert another <Activity>SomeGUID</Activity> into the <Spawned> parent.
Any help is greatly appreciated.
Thanks.
Edited by: 943783 on Dec 14, 2012 12:58 PMSee XML updating functions : http://docs.oracle.com/cd/E11882_01/appdev.112/e23094/xdb04cre.htm#i1032611
For example :
UPDATE my_table t
SET t.my_clob =
XMLSerialize(document
insertChildXML(
XMLParse(document t.my_clob)
, '/Activity/Spawned'
, 'Activity'
, XMLElement("Activity", 'Some GUID')
WHERE ...
;Although it works, there's overhead introduced by parsing the CLOB, then serializing again.
Is there any chance you can change the CLOB to SECUREFILE binary XMLType storage instead?
You would then be able to benefit from optimized piecewise update of the XML and improved storage. -
Reading Xml file from clob column in the staging table
Hi,
I am trying to poll the staging table with the database adapter which has CLOB column type containing XML file. How do I extract the XML file from CLOB and map the fields to the another variable with definite schema.
Thanks,
Edited by: chaitu123 on Sep 20, 2009 8:16 AM1) when you create DBAdapter on a table which having the clob column watch closely the created xsd for the DBAdapter the clob cloumn element should be a String data type
2) create xsd for Xml File and create variable for the xsd element
3) use ora:parseEscapedXML("yourDBAdapterclobElement") to XmlFileVarilable
Krishna -
Read text file into clob column
Dear Oracle users and Oracle support,
I have a text file that includes hundreds of data entries. The format is below. What I need to do is read each entry (
<DATALOAD ................</DATALOAD>) into the CLOB column as a table record. Then create a loop in the table to convert each record into XML data type. I have general idea on how to convert CLOB to XML. The difficult part to me is read the each entry in the text file to CLOB table. Please let me know what technique I should use. Any recommendation and sample code are welcome! I appreciate!
Thanks,
Bing
<DATALOAD ................</DATALOAD>
<DATALOAD ................</DATALOAD>
<DATALOAD ................</DATALOAD>
<DATALOAD ................</DATALOAD>RBYL wrote:
Hi,
Thank you for your response. What I want to achieve is read the text file into ClOB column. There are hundreds reocords in the text file. The format is below. Each entry is '<DATALOAD (sensitive data here, use....... instead)</DATALOAD>' that needs to be read into clob table as a record. That is basically what I need to achieve.
<DATALOAD ................</DATALOAD>
<DATALOAD ................</DATALOAD>
hundreds of them here........
<DATALOAD ................</DATALOAD>
<DATALOAD ................</DATALOAD>So, is it really a text file or is it a well structured XML file?
Just reading it into a CLOB to process is not likely to be the best way.
If each line of the file is a record, then you're likely to be better using something like External Tables.
If it's a structured XML file, then it can be read using CLOB functionality into an XMLTYPE datatype and then shredded down into relational table structures.
Be more clear in what your requirements are and we can help you better.
{message:id=9360002} -
How to retreive soap xml data from clob column in a table
Hi,
I am trying to retrieve the XML tag value from clob column.
Table name = xyz and column= abc (clob datatype)
data stored in abc column is as below
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:head="http://www.abc.com/gcgi/shared/system/header" xmlns:v6="http://www.abc.com/gcgi/services/v6_0_0_0" xmlns:sys="http://www.abc.com/gcgi/shared/system/systemtypes">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<RqHeader soapenv:mustUnderstand="0" xmlns="http://www.abc.com/gcgi/shared/system/header">
<DateAndTimeStamp>2011-12-20T16:02:36.677+08:00</DateAndTimeStamp>
<UUID>1000002932</UUID>
<Version>6_0_0_0</Version>
<ClientDetails>
<Org>ABC</Org>
<OrgUnit>ABC</OrgUnit>
<ChannelID>HBK</ChannelID>
<TerminalID>0000</TerminalID>
<SrcCountryCode>SG</SrcCountryCode>
<DestCountryCode>SG</DestCountryCode>
<UserGroup>HBK</UserGroup>
</ClientDetails>
</RqHeader>
<wsa:Action>/SvcImpl/bank/
SOAPEndpoint/AlertsService.serviceagent/OpEndpointHTTP/AlertDeleteInq</wsa:Action></soapenv:Header>
<soapenv:Body>
<v6:AlertDeleteInqRq>
<v6:Base>
<v6:VID>20071209013112</v6:VID>
<!--Optional:-->
<v6:Ref>CTAA00000002644</v6:Ref>
</v6:Base>
</v6:AlertDeleteInqRq>
</soapenv:Body>
</soapenv:Envelope>
And i want to retrieve the values of tag
<ChannelID> and <v6:VID>
can somebody help, i have tried with extractvalue but not able to get the valuesI have used the below two queries but not able to get the expected results. Both queries result into no values.
select xmltype(MED_REQ_PAYLOAD).extract('//ClientDetails/Org','xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" || xmlns="http://www.abc.com/gcgi/shared/system/header"').getStringValue() from ESB_OUTPUT_TEMP where SOAPACTION = '/SvcImpl/bank/alerts/v6_0_0_0/SOAPEndpoint/AlertsService.serviceagent/OpEndpointHTTP/AlertDeleteInq'
select EXTRACTVALUE(xmltype(MED_REQ_PAYLOAD),'/RqHeader/) from ESB_OUTPUT_TEMP where SOAPACTION = '/SvcImpl/bank/SOAPEndpoint/AlertsService.serviceagent/OpEndpointHTTP/AlertDeleteInq'
Well, for starters, both queries are syntactically wrong :
- non terminated string
- incorrect namespace mapping declaration
- unknown XMLType method "getStringValue()"
Secondly, all those functions are deprecated now.
Here's an up-to-date example using XMLTable. It will retrieve the two tag values you mentioned :
SQL> select x.*
2 from esb_output_temp t
3 , xmltable(
4 xmlnamespaces(
5 'http://schemas.xmlsoap.org/soap/envelope/' as "soap"
6 , 'http://www.abc.com/gcgi/shared/system/header' as "head"
7 , 'http://www.abc.com/gcgi/services/v6_0_0_0' as "v6"
8 )
9 , '/soap:Envelope'
10 passing xmlparse(document t.med_req_payload)
11 columns ChannelID varchar2(10) path 'soap:Header/head:RqHeader/head:ClientDetails/head:ChannelID'
12 , VID varchar2(30) path 'soap:Body/v6:AlertDeleteInqRq/v6:Base/v6:VID'
13 ) x
14 ;
CHANNELID VID
HBK 20071209013112
You may also want to store XML in XMLType columns for both performance and storage optimizations.
Maybe you are looking for
-
hai ashrivastava.. thank u for sending this one..now i got some more problems with that screen .. actually i am added one JPanel to JFrame with BorderLayout at south..the problem is when i am drawing diagram..the part of diagram bellow JPanel is now
-
When I connect my external screen ( iiyama vision master pro 410 ) to my macbook via the mini dvi to vga connector the screen of the iiyama is blurred. ( not just the text, everything ) It is on it's native resolution, and if i hook up any other pc t
-
I have recently updated my macbook pro as I had some pending software updates. I left it to do the job over night and the next day I noticed it was not letting me sign in to my account session as usual. I restarted the computer and ever since then wh
-
OT: 2 Video card - Macpro quad
Has anyone tried hooking up 4 monitors to one of the babies yet?
-
Hi guys, I have a selection screen consisting of two fields...... 1. Master Invoice No. and 2. Creation date My Requirement is when date ranges are used in selection, i need to filter only master invoices that are within this date range. Please help