Problem with DBMS_LOB.SUBSTR
Hi,
i want to encode a BLOB into BASE64_ENCODE.
Here my PL/SQL function:
FUNCTION encodeBlob2Base64(pBlobIn IN BLOB)
RETURN BLOB
IS
vAmount PLS_INTEGER := 20000;
vBase64Blob BLOB;
vBlobIn BLOB;
vOffset PLS_INTEGER := 1;
BEGIN
vBlobIn := pBlobIn;
dbms_lob.createtemporary(lob_loc => vBase64Blob, CACHE => FALSE);
LOOP
dbms_lob.append(dest_lob => vBase64Blob,
src_lob => utl_encode.base64_encode(r =>
dbms_lob.substr(lob_loc => vBlobIn, amount => vAmount, offset => vOffset)));
vOffset := vOffset + vAmount;
END LOOP;
dbms_lob.freetemporary(lob_loc => vBase64Blob);
RETURN vBase64Blob;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END encodeBlob2Base64;
When i now use my function i get the ORA-29261: bad argument in the statement DBMS_LOB.SUBSTR(lob_loc ...)
Has somebody an idea, what's wrong?
Many thanks in advance.
Regards,
Martin
The reason is that utl_encode returns a raw whereas dbms_lob.append expects either a blob or a clob.
SQL> desc utl_encode;
FUNCTION BASE64_DECODE RETURNS RAW
Argument Name Type In/Out Default?
R RAW IN
FUNCTION BASE64_ENCODE RETURNS RAW
Argument Name Type In/Out Default?
R RAW IN
FUNCTION MIMEHEADER_DECODE RETURNS VARCHAR2
Argument Name Type In/Out Default?
BUF VARCHAR2 IN
FUNCTION MIMEHEADER_ENCODE RETURNS VARCHAR2
Argument Name Type In/Out Default?
BUF VARCHAR2 IN
ENCODE_CHARSET VARCHAR2 IN DEFAULT
ENCODING BINARY_INTEGER IN DEFAULT
FUNCTION QUOTED_PRINTABLE_DECODE RETURNS RAW
Argument Name Type In/Out Default?
R RAW IN
FUNCTION QUOTED_PRINTABLE_ENCODE RETURNS RAW
Argument Name Type In/Out Default?
R RAW IN
FUNCTION TEXT_DECODE RETURNS VARCHAR2
Argument Name Type In/Out Default?
BUF VARCHAR2 IN
ENCODE_CHARSET VARCHAR2 IN DEFAULT
ENCODING BINARY_INTEGER IN DEFAULT
FUNCTION TEXT_ENCODE RETURNS VARCHAR2
Argument Name Type In/Out Default?
BUF VARCHAR2 IN
ENCODE_CHARSET VARCHAR2 IN DEFAULT
ENCODING BINARY_INTEGER IN DEFAULT
FUNCTION UUDECODE RETURNS RAW
Argument Name Type In/Out Default?
R RAW IN
FUNCTION UUENCODE RETURNS RAW
Argument Name Type In/Out Default?
R RAW IN
TYPE BINARY_INTEGER IN DEFAULT
FILENAME VARCHAR2 IN DEFAULT
PERMISSION VARCHAR2 IN DEFAULT
SQL> spool off
Similar Messages
-
Problem with DBMS_LOB.
Hi, I am working with Oracle XE, I created a table with the following structure:
CREATE TABLE "HR". EMPLOYEE_DOCUMENTS "
"NUM_DOCUMENS" ENABLE NUMBER NOT NULL,
"EMPLOYEE_COD" NUMBER (6.0) NOT NULL ENABLE,
"TIPO_DOCUMENTO" VARCHAR2 (12 BYTE) NOT NULL ENABLE,
"GENERADO_EL" DATE NOT NULL ENABLE,
"DOCUMENTO_BLOB" BLOB,
"DOCS8_CLOBS" CLOB,
CONSTRAINT "EMPLOYEE_DOCUMENTS_PK" PRIMARY KEY ( "NUM_DOCUMENS")
In the field CLOB stored as a text as follows:
A person who carries the card. # for the use of the credential # pursued by the law.
With DBMS_LOB, replacing the characters # content in the field CLOB by the value 1306958172, but the text that remains the last # concatenates and not get results like this:
A person who carries the card. 1306958172 for the use of the credential 1306958172 pur
One more question, as can assign field contents CLOb the type BLOB field to save as a Word document, an example please.
Tahnk.
Roberto.In that place of my Store Procedure:
declare
clobs1 CLOB;
clobs2 CLOB;
BLOBS blob;
clobs_aux CLOB;
valor number;
cadena varchar2(4000);
nposicion number;
ncontar number:=1;
begin
select docs8_clobs, documento_blob into clobs1,blobs
from hr.EMPLOYEE_DOCUMENTS
where hr.EMPLOYEE_DOCUMENTS.NUM_DOCUMENS=12812;
valor:=DBMS_LOB.INSTR(CLOBS1,'#',1,ncontar);
clobs_aux:=clobs1;
while valor<>0 loop
nposicion:=valor+1;
DBMS_OUTPUT.PUT_LINE(TO_CHAR(VALOR));
clobs2:=DBMS_LOB.SUBSTR(clobs_aux,valor-1,1);
clobs2:=clobs2||' '||to_clob('1306958172');
clobs2:=clobs2||' '||DBMS_LOB.SUBSTR(clobs_aux,nposicion,nposicion);
CLOBS_AUX:=CLOBS2;
if ncontar>=1 then
update hr.EMPLOYEE_DOCUMENTS
set docs8_clobs=clobs_aux
where num_documens=12812;
commit;
end if;
--Recuperar campo CLOB actualizado.
select docs8_clobs, documento_blob into clobs1,blobs
from hr.EMPLOYEE_DOCUMENTS
where hr.EMPLOYEE_DOCUMENTS.NUM_DOCUMENS=12812;
CLOBS_AUX:=CLOBS1;
valor:=DBMS_LOB.INSTR(CLOBS_AUX,'#',1,ncontar);
ncontar:=ncontar+1;
end loop;
end;
Roberto. -
Problem with DBMS_LOB.append() procedure
Hi all.
I have a small question about this function:
I tried to use it to unit 2 CLOB objects. Here is part of my script:
create or replace
procedure PAGE_CSV()
is
S clob;
S_FULL clob;
begin
DBMS_LOB.append(S_FULL, S);
end;
But I've got an error:
ORA-19011: Character string buffer too small
May be somebody knows what about his error? I Can not realize why it's about buffer (looks like varchar2), I do not use it...
Thanks,
Anton.
PS Thats for sure, both of objects are not null.
Edited by: user9050456 on Feb 9, 2010 5:44 AMYou cannot assign to a lob variable a value larger then 32767 bytes if it doesn't have a persistent storage in the DB.
SQL> declare
2 a clob;
3 begin
4 a:=lpad('x',4001,'x');
5 dbms_output.put_line(a);
6 end;
7 /
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PL/SQL procedure successfully completed.
SQL> declare
2 a clob;
3 begin
4 a:=lpad('x',32768,'x');
5 dbms_output.put_line(a);
6 end;
7 /
declare
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 4You have to do something like this:
CREATE OR REPLACE PROCEDURE Example_1a IS
dest_lob BLOB;
src_lob BLOB;
BEGIN
-- get the LOB locators
-- note that the FOR UPDATE clause locks the row
SELECT b_lob INTO dest_lob
FROM lob_table
WHERE key_value = 12 FOR UPDATE;
SELECT b_lob INTO src_lob
FROM lob_table
WHERE key_value = 21;
DBMS_LOB.APPEND(dest_lob, src_lob);
COMMIT;
EXCEPTION
WHEN some_exception
THEN handle_exception;
END;Where both the source LOB and the destination one have a persistent storage on db.
Max
[My Italian Oracle blog| http://oracleitalia.wordpress.com/2010/02/07/aggiornare-una-tabella-con-listruzione-merge/] -
Dbms_lob.substr is failing with ORA-06502
The following query is throwing error while doing minus with dbms_lob.substr although 4000
characters are being selected. Column billing_inventory is of CLOB. Please advice.
SQL> select count(1) from llums_feed;
724754
SQL> select count(1) from llums_feed_prv;
0
SQL> SELECT
asset_id,dbms_lob.substr(billing_inventory,4000,1),dbms_lob.substr(billing_inventory,8000,4001)
FROM llums_feed
minus
select asset_id, dbms_lob.substr(billing_inventory,4000,1)
,dbms_lob.substr(billing_inventory,8000,4001)
from llums_feed_prv;
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 1Hello
You are selecting 8000 characters from position 4001, not 4000 characters from position 4001....
FUNCTION substr(lob_loc IN BLOB,
amount IN INTEGER := 32767,
offset IN INTEGER := 1)dbms_lob.substr(billing_inventory,4000,1),dbms_lob.substr(billing_inventory,8000,4001)
You need to modify the 2nd substr in each select statement to be
dbms_lob.substr(billing_inventory,4000,1),dbms_lob.substr(billing_inventory,4001,4000)
HTH
David
Edited by: David Tyler on Jun 27, 2011 1:16 PM -
Problem with substring in xsl file?
Hallo,
i have a xsl file, when using
<xsl:value-of select="StsEdat"/> i've got 2007-05-21, that's o.k.
when using <xsl:value-of select="substring(StsEdat,9,2)"/> the answer is blank.
also 0,5 or so on. substring at this position delivers blank. why?
what can it be? i'am helpless.
any help is appreciated.Hi,
I used <xsl:value-of select="substring(StartDate,9,2)"/> the answer was 21 and to 0,5 the answer was 2007. It seems that's ok!
Try to do it and see if you have problem with substring.
<xsl:variable name="StsEdat">2007-05-21</xsl:variable>
<xsl:value-of select="substring($StsEdat,9,2)"/>
or this weird way, :)
<xsl:variable name="StsEdat">2007-05-21</xsl:variable>
<xsl:value-of select='substring-after(substring-after($StsEdat, "-"), "-")' />
Regards,
Cleiton -
Problem with SUBSTR and GROUP BY
Hi people...
I'm needing a little help with this case. I'm executing this SQL and got error ORA-01722. I've tried to use number columns, alias and the syntax below and always got error. My problem is the SUBSTR, without it I can run the SQL with no error.
SQL> ED
Gravou arquivo afiedt.buf
1 SELECT TO_CHAR(DATA,'DD/MM') AS DATA,
2 SUBSTR(TO_CHAR(DATA,'DAY'),1,3) AS DIA_SEM,
3 SUM(DECODE(TIPOBAIXA,1,1,0)) AS INST,
4 SUM(DECODE(TIPOBAIXA,1,0,1)) AS REM,
5 SUM(DECODE(TIPOBAIXA,1,1,0))-SUM(DECODE(TIPOBAIXA,1,0,1)) AS DIFF
6 FROM BAIXA
7 GROUP BY TO_CHAR(DATA,'DD/MM'), TO_CHAR(DATA,'DAY')
8* ORDER BY TO_CHAR(DATA,'DD/MM') DESC
SQL> /
GROUP BY TO_CHAR(DATA,'DD/MM'), TO_CHAR(DATA,'DAY')
ERRO na linha 7:
ORA-01722: invalid number
Somebody has an idea of how I can solve this?
Thanks,
FabianoSQL> create table baixa
2 as
3 select sysdate data, 1 tipobaixa from dual union all
4 select sysdate - 1, 0 from dual union all
5 select sysdate - 2, 1 from dual
6 /
Tabel is aangemaakt.
SQL> SELECT TO_CHAR(DATA,'DD/MM') AS DATA
2 , TO_CHAR(DATA,'DY') AS DIA_SEM
3 , SUM(DECODE(TIPOBAIXA,1,1,0)) AS INST
4 , SUM(DECODE(TIPOBAIXA,1,0,1)) AS REM
5 , SUM(DECODE(TIPOBAIXA,1,1,0))-SUM(DECODE(TIPOBAIXA,1,0,1)) AS DIFF
6 FROM BAIXA
7 GROUP BY TO_CHAR(DATA,'DD/MM'), TO_CHAR(DATA,'DY')
8 ORDER BY TO_CHAR(DATA,'DD/MM') DESC
9 /
GROUP BY TO_CHAR(DATA,'DD/MM'), TO_CHAR(DATA,'DY')
FOUT in regel 7:
.ORA-01722: invalid number
SQL> select to_char(data,'dd/mm') as data
2 , to_char(data,'DY') as dia_sem
3 , sum(decode(tipobaixa,1,1,0)) as inst
4 , sum(decode(tipobaixa,1,0,1)) as rem
5 , sum(decode(tipobaixa,1,1,0))-sum(decode(tipobaixa,1,0,1)) as diff
6 from baixa
7 group by to_char(data,'dd/mm')
8 , to_char(data,'DY')
9 order by 1 desc
10 /
DATA DI INST REM DIFF
05/01 VR 1 0 1
04/01 DO 0 1 -1
03/01 WO 1 0 1
3 rijen zijn geselecteerd.Regards,
Rob. -
DBMS_LOB.SUBSTR with NCLOB data type
Hi ,
When I am trying to extract part of the string from Comments column(NCLOB datatype) am facing issue.
ORA-06502:PL/SQL Numeric or value error :Character string buffer too small
select dbms_lob.substr(a.COMMENTS, 4000, 1),
from VW_DETAILS a
where a.id = 6210872
DBMS_LOB.SUBSTR with NCLOB data type
Table structure :
Column_name Data_type
Comments NCLOB
ID NUMBER
Regards,
VenkatDBMS_LOB.SUBSTR parameter amount for CLOB/NCLOB indicates number of characters to substring, not bytes. And 4000 multi-byte characters (since you are using NCLOB) is greater than 4000 bytes which is absolute limit for VARCHAR2 in SQL.
SY. -
Dbms_lob.substr ( difference with simple function substr)
Hello suppose the following query
SELECT employee_id, resume,
DBMS_LOB.SUBSTR (resume, 5, 18) lob_substr,
substr(resume, 5, 18) sub
FROM employees
WHERE employee_id = 170;
resume is of CLOB datatype
and for employee_id 170 is 'Date of Birth: 1 June 1956 Resigned: 30 September 2000'
the results are:
sub
' of Birth: 1 June '
I understand that.
I cannot understand why DBMS_LOB.SUBSTR (resume, 5, 18) gives as a result
'June '
Thank you.
What is the difference?Sorry, I found the answer myself.
dms_lob.substr is different from function substr
DBMS_LOB.SUBSTR(lob_column, no_of_chars, starting)
no_of_chars : how many characters it will return, so in my example, 5 characters will be returned, that's why 'June '
starting from position 18 -
Here's my code..
String Varble = rs0.getString("adddate").substring(0,10);
out.println("<td>" + stmt + "</td>");
I've also tried this (which is the same thing just more code) Now it DOES work if I make tinydate text.
String tinydate = rs0.getString("adddate")
String Varble = tinydate.substring(0,10);
out.println("<td>" + stmt + "</td>");
Here's the Error. What am I doing wrong?
javax.servlet.ServletException: Error: Browse.jsp - select adddate from K9Manager WHERE adddate is not NULL failed.java.sql.SQLException: [TDS Driver]No current row[TDS Driver]No current row
Hard to tell what you are doing wrong, but it is nothing to do with the substring method. The message "No current row" suggests to me that you haven't called rs0.next() to move to the first row of the result set, but the error message displays your SQL, which I find strange. But maybe that's just how your JDBC driver does things.
-
Oracle error while using function dbms_lob.substr()
Following sql statement is causing error select dbms_lob.substr(clob_colum,32767) from Table* when the size of clob_column goes above 4 KB. The error message is given below
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 1
The issue is getting resolved when reducing the size of the CLOB column.
Is this a limitation of oracle query? Can anybody please help me to resolve this error? Thanks in Advance.
Regards,
ShineHi.
>
We are using this query inside a package and the data is used to generate an XML file and it finally used to generate a pdf report. There exists many clob records with huge size and in that case report execution fails with the oracle message.
>
While the XML file is generated or PDF report?
Which message? ORA-06502: PL/SQL: numeric or value error: character string buffer too small ???
>
So we need to modify the query in a way that it executes fine even if the size is more than 4 KB(upto a possible size). I tried using substr function against the clob column but it does not returned any value.
>
Then, do you need the first 4 KB or the entire CLOB?
Can't you write CLOB directly?
Please post some example data as well as your desired output in order to understand completely your problem and test our ideas.
Regards. -
DBMS_LOB.SUBSTR() returning 8191 characters instead of 32767
Hi all,
I just run into an interesting issue.
Trying to convert a CLOB to VARCHAR2(32767) I only got 8191 characters.
Here is a code sample:
DECLARE
v_clob clob := '';
v_vchar VARCHAR2(32767);
j INTEGER := 0;
BEGIN
FOR i IN 1..32767 LOOP
v_clob := v_clob || to_char(j);
j := j + 1;
IF j = 10 THEN
j := 0;
END IF;
END LOOP;
v_vchar := dbms_lob.substr(v_clob, 32767, 1);
dbms_output.put_line('Length: ' || length(v_vchar));
dbms_output.put_line('First: ' || substr(v_vchar, 1, 1));
dbms_output.put_line('Last: ' || substr(v_vchar, length(v_vchar), 1));
END;
Looking at this one should expect the length to be 32767, the first character in the v_vchar variable - 0 and the last one - 6, right? Unfortunately here is the output I get:
Length: 8191
First: 0
Last: 0
Running trough some google searches I only found a couple of posts regarding the issue and no reasonable explanation or fix, workaround or something. A guy had the same problem and his conclusion was that it was a platform dependent issue - he got the same result using DBMS_LOB.SUBSTR() on Oracle running on Solaris and the correct result running on a Windows Server.
Reading those few posts made me think that's a bug.
My platform - Oracle 10g running on Linux. I haven't tried it on a Windows (that's not my point).
Any help / ideas / explanations would be highly appreciated! :-)Thank you very much for this quick and exact response.
DBMS_LOB.READ worked fine.
Unfortunately I can find no information about this bug - can you help me with that?
Thanks once again!
Cheers -
Problem with My Base64 Encoding CLOB Routine.
I have written a program which reads an xml file into the database
and makes it Base64encoded.
This needs to work on 10g and above
If the read length specified in the code below is greater than the length of the xml_file, then I get the expected result(output).
However if the read length is less than the length of the file, then I get a lot of '==' in the file and as a result, incorrect encoding which means that the file will not be readable through the application.
I'm pretty sure I'm reading the blob lengths correctly, and the problem is somehow related to the base64 encoding.Any help appreciated
[create or replace profile_dir as &profile_dir;
create global temporary table load_xml
(profile_text clob)
on commit delete rows;
create or replace
procedure encode_xml_clobs(p_file_in in varchar2,
p_clob_out out nocopy clob )
as
pragma autonomous_transaction;
dest_clob CLOB;
src_clob BFILE := BFILENAME('PROFILE_DIR', p_file_in);
dst_offset number := 1 ;
src_offset number := 1 ;
lang_ctx number := DBMS_LOB.DEFAULT_LANG_CTX;
warning number;
-- processing declarations for encoding base64 --
v_xml_string varchar2(32767);
v_string varchar2(32767);
v_start_pos number := 0;
v_read_length number := 1000;
v_final_start_pos number;
v_clob_length number;
type clob_array_type is table of clob index by binary_integer;
clob_array clob_array_type;
v_index number :=0;
-- Declarations for converting base64encoded string to a clob
v_encoded_length number;
v_temp_clob clob;
BEGIN
-- THE FOLLOWING BLOCK OF CODE WILL ATTEMPT TO INSERT / WRITE THE CONTENTS
-- OF AN XML FILE TO A CLOB COLUMN. IN THIS CASE, WE WILL USE THE NEW
-- DBMS_LOB.LoadCLOBFromFile() API WHICH *DOES* SUPPORT MULTI-BYTE
-- CHARACTER SET DATA.
-- load_xml should be a Global temporary table with on commit delete rows
INSERT INTO load_xml(profile_text)
VALUES( empty_clob())
RETURNING profile_text INTO dest_clob;
-- OPENING THE SOURCE BFILE IS MANDATORY
DBMS_LOB.OPEN(src_clob, DBMS_LOB.LOB_READONLY);
DBMS_LOB.LoadCLOBFromFile(
DEST_LOB => dest_clob
, SRC_BFILE => src_clob
, AMOUNT => DBMS_LOB.GETLENGTH(src_clob)
, DEST_OFFSET => dst_offset
, SRC_OFFSET => src_offset
, BFILE_CSID => DBMS_LOB.DEFAULT_CSID
, LANG_CONTEXT => lang_ctx
, WARNING => warning
DBMS_LOB.CLOSE(src_clob);
-- DBMS_OUTPUT.PUT_LINE('Loaded XML File using DBMS_LOB.LoadCLOBFromFile: (ID=1');
-- file now successfully loaded
select dbms_lob.GETLENGTH(profile_text)
into v_clob_length
from load_xml;
-- File now loaded in temporary table
-- we now need to take the clob , convert it to varchar2
v_read_length :=64;
v_xml_string := '';
while v_start_pos <= v_clob_length
loop
v_index := v_index + 1;
v_string := '';
--dbms_output.put_line('Start_pos=>'||(v_start_pos+1)||' Read Length=>'||v_read_length);
--encode base64
select utl_raw.cast_to_varchar2(
utl_encode.base64_encode(
utl_raw.cast_to_raw(dbms_lob.substr(profile_text,least(v_read_length,v_clob_length-v_start_pos),v_start_pos+1))
into v_string
from load_xml;
--dbms_output.put_line(v_string);
v_start_pos := v_start_pos+v_read_length;
clob_array(v_index) := v_string;
end loop;
p_clob_out := clob_array(1);
for i in 2 .. v_index
loop
dbms_lob.append(p_clob_out,clob_array(i));
end loop;
commit;
END;Base64 encoding encodes every 3 bytes of input data into 4 bytes of output data. It uses equal signs to indicate nodata and only at the end of the encoded sequence. Try chaning your v_read_length parameter to a multiple of 3 e.g. 960 or 1008 instead of the current 1000. I'm using multiples of 48 because the utl_encode.base64_encode function adds a linebreak for every 48 bytes of input data (64 bytes of output). If you use a value that's not divisible by 48 you will still get a legitimate encoding as long as it's divisible by 3, but you will get some lines longer than others when you append them together.
-
Problem with analytic function
Hi ,
I have table with fields :
ID ,BUG_ID ,COMMENT_TEXT
sample values are
ID BUG_ID COMMENT_TEXT
1 2 test1
2 3 test1
3 2 test2
4 5 test1
5 5 test2
6 2 test3
and I am using following script to get the output
like :
BUG_ID CMNT_TEXT1 COMNT_TEXT2 CMNT_TEXT3
2 test1 test2 test3
3 test1
5 test1 test2
SQL Script is :
select bug_id,
max(decode(seq_no,1,DBMS_LOB.substr(ctext,4000,1))) as comment_text1,
max(decode(seq_no,2,DBMS_LOB.substr(ctext,4000,1))) as comment_text2,
max(decode(seq_no,3,DBMS_LOB.substr(ctext,4000,1))) as comment_text3,
max(decode(seq_no,4,DBMS_LOB.substr(ctext,4000,1))) as comment_text4,
max(decode(seq_no,5,DBMS_LOB.substr(ctext,4000,1))) as comment_text5
from (
select bug_id,
ctext,
row_number() over
(partition by bug_id order by bug_id) as seq_no
from phpbt_dblearn_comment
group by bug_id
but it is always first values ( eg test1 for bug_id 2 , test1 for bug_id 5 ) are missing if i run this script.
Please could someone tell me What is wrong with this script ?
regards,
KarnaHi Karna,
maybe i don't see the problem but that's what i get from my tests:
ID BUG_ID CTEXT
1 2 test1
2 3 test1
3 2 test2
4 5 test1
5 5 test2
6 2 test3
6 Zeilen ausgewählt.
select bug_id,
max(decode(seq_no,1,DBMS_LOB.substr(ctext,4000,1))) as comment_text1,
max(decode(seq_no,2,DBMS_LOB.substr(ctext,4000,1))) as comment_text2,
max(decode(seq_no,3,DBMS_LOB.substr(ctext,4000,1))) as comment_text3,
max(decode(seq_no,4,DBMS_LOB.substr(ctext,4000,1))) as comment_text4,
max(decode(seq_no,5,DBMS_LOB.substr(ctext,4000,1))) as comment_text5
from (
select bug_id,
ctext,
row_number() over
(partition by bug_id order by id) as seq_no
from test2
group by bug_id;
BUG_ID COMMENT_TEXT1 COMMENT_TEXT2 COMMENT_TEXT3 COMMENT_TEXT4 COMMENT_TEXT5
2 test1 test2 test3
3 test1
5 test1 test2
3 Zeilen ausgewählt.
I thought that's what you're lokking for.
Regards,
Alexander -
Usage of dbms_lob.substr()
Hi all,
I have a question to the usage of dbms_lob.substr function in PL/SQL.
I have a clob with dbms_lob.getlength(l_clob) = 12295.
When I call dbms_lob.substr to get the clob starting from the specified location, I miss
data at the end of the result clob.
declare
l_clob clob;
l_result_clob clob;
l_len number;
begin
l_len := dbms_lob.getlength(l_clob); -- len => 12295
l_result_clob := dbms_lob.substr(l_clob, 12239, 56);
l_len := dbms_lob.getlength(l_result_clob); -- len => 10958
end;
/With a smaller clob there are no such problems.
Any Idea what happend?
Thanks
Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
NLS_CHARACTERSET AL32UTF8
NLS_NCHAR_CHARACTERSET AL16UTF16Thank you very much for this quick and exact response.
DBMS_LOB.READ worked fine.
Unfortunately I can find no information about this bug - can you help me with that?
Thanks once again!
Cheers -
Problem with Collections after Upgrade to Apex 4.02
Hi,
We are using oracle 10g with Apex 4.02.
I installed Jari's application for data import from excel.
http://dbswh.webhop.net/apex/f?p=BLOG:READ:0::::ARTICLE:126300346812330
It is working fine in our test environment but in production environment it is showing no data when I press the submit button. Am I missing some user privillege? Any help?
Thanks,
ZahidI have a HTML page with a browse file item. I select my csv file and press the upload button. The button submits the page and executes the following procedure.
BEGIN
DECLARE
v_blob_data BLOB;
v_blob_len NUMBER;
v_position NUMBER;
v_raw_chunk RAW(10000);
v_char CHAR(1);
c_chunk_len number := 1;
v_line VARCHAR2 (32767) := NULL;
v_data_array wwv_flow_global.vc_arr2;
v_rows number;
v_sr_no number := 1;
v_rows_loaded NUMBER;
BEGIN
-- Read data from wwv_flow_files</span>
select blob_content into v_blob_data
from wwv_flow_files
where last_updated = (select max(last_updated) from wwv_flow_files where UPDATED_BY = :APP_USER)
and id = (select max(id) from wwv_flow_files where updated_by = :APP_USER);
v_blob_len := dbms_lob.getlength(v_blob_data);
v_position := 1;
-- Read and convert binary to char</span>
WHILE ( v_position <= v_blob_len ) LOOP
v_raw_chunk := dbms_lob.substr(v_blob_data,c_chunk_len,v_position);
v_char := chr(hex_to_decimal(rawtohex(v_raw_chunk)));
v_line := v_line || v_char;
v_position := v_position + c_chunk_len;
-- When a whole line is retrieved </span>
IF v_char = CHR(10) THEN
-- Convert comma to : to use wwv_flow_utilities </span>
v_line := REPLACE (v_line, ',', ':');
-- Convert each column separated by : into array of data </span>
v_data_array := wwv_flow_utilities.string_to_table (v_line);
--DELETE OLD DATA
-- Insert data into target table </span>
IF v_sr_no >1 THEN
EXECUTE IMMEDIATE 'INSERT INTO EMP(EMPNO, ENAME, SAL, COMM, DEPTNO)
VALUES (:1, :2, :3, :4, :5)'
USING
-- v_sr_no,
v_data_array(1),
v_data_array(2),
v_data_array(3),
v_data_array(4),
v_data_array(5);
END IF;
-- Clear out
v_line := NULL;
v_sr_no := v_sr_no + 1;
END IF;
END LOOP;
END;
COMMIT;
END;Pressing button gives me "ORA-01403: no data found" error message. This has been working before we upgraded from Apex 3.2 to Apex 4.02.
I hope that the above detail may give you better idea of the problem.
Thanks.
Maybe you are looking for
-
How to fetch the value of tabular form item in javascript
Hello all I want to do some calculations on the value entered by the user in the textfield of a tabular form, how can I fetch the value of tabular form item in the javascript? I am using normal tabular form, not using apex_item tabular form. I can pa
-
64bit Vista and iTunes/iPhone
My new PC has Vista 64bit on it. I installed the 64bit iTunes and it seemed to install correctly but it doesn't recognize the iPhone. My iPod connects fine but the iPhone doesn't. I was on the phone with Apple tech support about an hour and finally t
-
Can I stop Apple from sending me an email every time I locate my device using Findmyiphone?
Apple sends me an email notification every time someone locates my iphone. Can I stop these emails?
-
Upgrade from Photoshop 7 to something that works on Intel Leopard Mac
I have Photoshop 7. I would like to upgrade to the lowest level of Photoshop that runs on an intel Mac with Leopard. What is the minimum version of Photoshop CS that runs on an Intel Mac with Leopard? Can I upgrade directly to that version, or will
-
Compiling in dependency classes
Is there a way to compile in all classes used by a Servlet into it, so that the only file to distribute is the Servlet. This is because I get the error: java.lang.NoClassDefFoundError: java/util/logging/Logger at adminServlet.(adminServlet.java:10) W