Dbms_lob.substr returns varchar2?????
I have a 400kb text string in a clob variable. I need to strip out certain characters to remove html tags. To do this I need to do lots of substr
This is taking a very long time and using massive amounts of temp tablespace, nearly 2GB!!
I'm trying to use dbms_lob.substr instread as I assume the issue is there are lots of clob to varchar2 conversions going on or something, still seems excessive that a 400kb file can consume nearly 2GB of temp tablespace!!
When I use dbms_lob.substr on the clob you cant return more than 32767 characters as it returns a varchar2, I need to to return a clob ... am I missing something as it seems ridiculous that dbms_lob.substr does not return a clob
My only work around is to have a varchar2(32767) array, break my clob down into chunks and, work with that and then stitch it all back together into a clob again ...... I'm hoping I am missing something and there is a better way
Thanks
Robert
At the moment I am just using substr, which does the job but takes a long time (over 20 minutes) and makes massive use of the temp tablespace
I calculated the size by using our test database with no users connected, made a single temp datafile of 500MB (which can auto extend) and when the routine had finished that file was 1.8GB.
I re-ran the routine again to make sure the time was not taken up resizing the temp tablespace and it took the same time.
Similar Messages
-
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 -
Dbms_lob.getlength() returns different values
Hi !
I am not a developer.. So, possibly cannot answer developer specific question.
We have two instances running on 10.2.0.4 but both giving different value for
declare
xml varchar2(32676) :=
'SELECT XT_STRATEGY, ACCT_DESCRIPTION,sum(MON_PL) PL_MON ,sum(TUE_PL) PL_TUE,sum(WED_PL) PL_WED ,sum(THU_PL) PL_THU, sum(FRI_PL) PL_FRI, sum(WTD_PL) PL_WTDPL,sum(WTD_PREMIUM_PL) PL_WTDPRMPL, sum(MTD_PL) PL_MARKPL,sum(MTD_PREMIUM_PL) PL_MTDPRMPL,sum(YTD_PL) PL_YTDPL,sum(YTD_PREMIUM_PL) PL_YTDPRMPL,
DLC_REGION,DLC_ENTITY FROM (SELECT xt_strategy, acct_description ,case when blankout_date < to_char( to_date( fv[EOD] )+ (1 -to_char(to_date(to_date( fv[EOD] )),''D''))) then 0 else MON_PL end as MON_PL, case when blankout_date < to_char( to_date( fv[EOD] )+ (1 -to_char(to_date(to_date( fv[EOD] )),''D''))) then 0 else tue_pl end as tue_pl,
case when blankout_date < to_char( to_date( fv[EOD] )+ (1 -to_char(to_date(to_date( fv[EOD] )),''D''))) then 0 else WED_PL end as WED_PL, case when blankout_date < to_char( to_date( fv[EOD] )+ (1 -to_char(to_date(to_date( fv[EOD] )),''D''))) then 0 else THU_PL end as THU_PL,
case when blankout_date < to_char( to_date( fv[EOD] )+ (1 -to_char(to_date(to_date( fv[EOD] )),''D''))) then 0 else FRI_PL end as FRI_PL, case when blankout_date < to_char( to_date( fv[EOD] )+ (1 -to_char(to_date(to_date( fv[EOD] )),''D''))) then 0 else WTD_PL end as WTD_PL,
case when blankout_date < to_char( to_date( fv[EOD] )+ (1 -to_char(to_date(to_date( fv[EOD] )),''D''))) then 0 else WTD_PREMIUM_PL end as WTD_PREMIUM_PL,
case when blankout_date < (select actual_date from tbl_date where date_type = ''PLMonthStart'' and to_char(actual_date, ''MMYYYY'') = to_char(to_date( fv[EOD] ),''MMYYYY'')) then 0 else mtd_pl end as mtd_pl,
case when blankout_date < (select actual_date from tbl_date where date_type = ''PLMonthStart'' and to_char(actual_date, ''MMYYYY'') = to_char(to_date( fv[EOD] ),''MMYYYY'')) then 0 else MTD_PREMIUM_PL end as MTD_PREMIUM_PL,
case when blankout_date < (select to_date(''01-JAN-''|| to_char(to_date((fv[EOD]),''DD-MON-YYYY''),''YYYY''),''DD-MON-YYYY'') from tbl_business_date) then 0 else ytd_PL end as ytd_PL,
case when blankout_date < (select to_date(''01-JAN-''|| to_char(to_date((fv[EOD]),''DD-MON-YYYY''),''YYYY''),''DD-MON-YYYY'') from tbl_business_date) then 0 else ytd_premium_PL end as ytd_premium_PL,
IN_STRIKECURR, IN_QUOTEDCUR, case dlc_region when ''LON'' then ''LN'' when ''NYC'' then ''NY'' when ''TOK'' then ''TK'' else dlc_region
end as DLC_REGION, DLC_ENTITY,DTL_REFERENCE,TRADE_STATE,blankout_date
FROM (select a.bo_book_id as xt_strategy, a.bo_book_id as acct_description , b.mon_pl, b.tue_pl, b.wed_pl,b.thu_pl,b.fri_pl,b.wtd_pl, b.wtd_premium_pl , b.mtd_pl , b.mtd_premium_pl, b.ytd_pl, b.ytd_premium_pl,
a.BASE_CCY as IN_STRIKECURR, A.QUOTED_CCY AS IN_QUOTEDCUR, a.region_code as dlc_region, a.entity_acronym as dlc_entity, TP.EBI_TRADE_ID AS DTL_REFERENCE, a.trade_state,
case when a.trade_state in (7,8,13) then a.amendment_date when a.maturity_date > nvl(a.premium_settlement_date, to_date(''01-JAN-1900'')) then
Case when a.trade_state in (4,5 ) then trunc(a.updated_date) else a.maturity_date end else a.premium_settlement_date end as blankout_date FROM TBL_TRADE_HIST A
join vw_feed_downstream_trade_id tp on a.trade_id = tp.trade_id and tp.mapping_source_name = ''ramfx''
join tbl_pl b on a.trade_id = b.trade_id and a.version = b.trade_version and b.pl_date = (select max(pl_date) from tbl_pl d where a.trade_id = d.trade_id and pl_date <= fv[EOD] )
join tbl_bo_book bk on a.bo_book_id = bk.bo_book_id and bk.business_Area = ''OPTIONS''
where b.pl_date < fv[EOD]
AND NOT EXISTS (SELECT 1 FROM TBL_EOD_TRADES D WHERE A.TRADE_ID = D.TRADE_ID AND D.BUSINESS_DATE = fv[EOD] )
UNION
SELECT A.XT_STRATEGY, A.ACCT_DESCRIPTION, C.MON_PL,C.TUE_PL, C.WED_PL,C.THU_PL, C.FRI_PL,C.WTD_PL,C.WTD_PREMIUM_PL,C.MTD_PL,C.MTD_PREMIUM_PL,C.YTD_PL,C.YTD_PREMIUM_PL,
A.IN_STRIKECURR, A.IN_QUOTEDCUR, A.DLC_REGION,A.DLC_ENTITY, A.DTL_REFERENCE , a.trade_state , case when a.trade_state in (7,8,13) then a.DLC_BUSDATEUPD when a.IN_EXPIRATION > nvl(a.XT_SETTLEDATE, to_date(''01-JAN-1900'')) then a.IN_EXPIRATION else a.XT_SETTLEDATE end as blankout_date
FROM VW_EBI_FEED A , TBL_EOD_TRADES B , TBL_PL C
WHERE A.TRADE_ID = B.TRADE_ID AND A.VERSION = B.TRADE_VERSION AND A.TRADE_ID = C.TRADE_ID
AND A.ACCT_RISKFEED = ''D'' AND A.DLC_DEALSTATE in (''LIVE'',''PENDING'',''CANCELLED'',''REVERSED'') AND A.VERSION = C.TRADE_VERSION
AND B.BUSINESS_DATE = to_date( fv[EOD] ,''DD-MON-YYYY'') AND C.PL_DATE = to_date( fv[EOD] ,''DD-MON-YYYY'')
UNION
SELECT A.BO_BOOK_ID AS XT_STRATEGY , A.BO_BOOK_ID AS ACCT_DESCRIPTION, a.MON_PL , a.TUE_PL , a.WED_PL, a.THU_PL , a.FRI_PL, a.WTD_PL ,a.WTD_PREMIUM_PL , a.mtd_pl, a.MTD_PREMIUM_PL,a.ytd_PL , a.ytd_premium_PL,A.BASE_CCY AS IN_STRIKECURR,A.QUOTED_CCY AS IN_QUOTEDCUR,
A.REGION_CODE as dlc_region ,A.ENTITY_ACRONYM AS DLC_ENTITY, A.MAPPING_SOURCE_ID AS DTL_REFERENCE, 12 as trade_state , a.PL_DATE as blankout_date
FROM TBL_PL_ARCH A , tbl_bo_book b where a.bo_book_id = b.bo_book_id and b.business_area = ''OPTIONS''
union
select d.bo_book_id as xt_strategy, d.bo_book_id as acct_description, case when to_char(b.pl_date,''D'') = 6 then (b.inception_pl + b.inception_premium_pl ) else (b.mon_pl * -1) end as mon_pl ,
case when to_char(b.pl_date,''D'') = 2 then (b.inception_pl + b.inception_premium_pl ) when to_char(b.pl_date,''D'') > 2 then (b.tue_PL * -1) else 0 end as tue_pl, case when to_char(b.pl_date,''D'') = 3 then (b.inception_pl + b.inception_premium_pl ) when to_char(b.pl_date,''D'') > 3 then (b.wed_pl * -1) else 0 end as wed_pl ,
case when to_char(b.pl_date,''D'') = 4 then (b.inception_pl + b.inception_premium_pl) when to_char(b.pl_date,''D'') > 4 then (b.thu_pl * -1) else 0 end as thu_pl ,case when to_char(b.pl_date,''D'') = 5 then (b.inception_pl + b.inception_premium_pl) when to_char(b.pl_date,''D'') > 5 then (b.fri_pl * -1) else 0 end as fri_pl ,
(b.mon_pl + b.tue_pl + b.wed_pl + b.thu_pl + b.fri_pl) * -1 + (b.inception_pl + b.inception_premium_pl) as wtd_pl, case when b.wtd_premium_pl <> 0 then b.wtd_premium_pl *-1 + (b.inception_premium_pl) else b.wtd_premium_pl end as wtd_premium_pl , case when b.mtd_pl <> 0 then b.mtd_pl * -1 + (b.inception_pl) else b.mtd_pl end as mtd_pl ,
case when b.mtd_premium_pl <> 0 then b.mtd_premium_pl * -1 + (b.inception_premium_pl ) else b.mtd_premium_pl end as mtd_premium_pl, case when b.ytd_pl <> 0 then b.ytd_pl * -1 + (b.inception_pl) else b.ytd_pl end as ytd_pl,
case when b.ytd_premium_pl <> 0 then b.ytd_premium_pl * -1 + (b.inception_premium_pl) else b.ytd_premium_pl end as ytd_premium_pl ,
c.base_ccy as IN_STRIKECURR,c.quoted_ccy as IN_QUOTEDCUR,c.region_code as dlc_region,c.entity_acronym as dlc_entity, to_char(c.trade_id) as dtl_reference,
8 as trade_state, case when to_char(b.pl_date,''D'') = 6 then b.pl_date + 2 else b.pl_date end as blankout_date
from tbl_trade_hist a
join tbl_pl b on a.trade_id = b.trade_id and a.version = b.trade_version
join tbl_trade_hist c on a.tradE_id = c.trade_id
join tbl_pl d on c.trade_id = d.trade_id and c.version = d.trade_version and d.pl_date = (select max(e.pl_date) from tbl_pl e where c.trade_id = e.trade_id and e.pl_date <= c.amendment_date)
join tbl_bo_book f on a.bo_book_id = f.bo_book_id and f.business_area = ''OPTIONS''
where (b.bo_book_id <> d.bo_book_id or a.region_code <> c.region_code or a.entity_acronym <> c.entity_acronym or a.base_ccy <> c.base_ccy or a.quoted_ccy <> c.quoted_ccy)
and d.pl_date - b.pl_date = case when to_char(d.pl_date,''DAY'') = ''MON'' then 3 else 1 end
and d.pl_date <= to_date( fv[EOD] ,''DD-MON-YYYY'')
union all
select b.bo_book_id as xt_strategy, b.bo_book_id as acct_description,case when to_char(b.pl_date,''D'') = 6 then (b.inception_pl * -1 + b.inception_premium_pl * -1) else (b.mon_pl ) end as mon_pl ,
case when to_char(b.pl_date,''D'') = 2 then (b.inception_pl * -1 + b.inception_premium_pl * -1) when to_char(b.pl_date,''D'') > 2 then (b.tue_PL) else 0 end as tue_pl, case when to_char(b.pl_date,''D'') = 3 then (b.inception_pl * -1 + b.inception_premium_pl * -1 ) when to_char(b.pl_date,''D'') > 3 then (b.wed_pl) else 0 end as wed_pl ,
case when to_char(b.pl_date,''D'') = 4 then (b.inception_pl * -1 + b.inception_premium_pl * -1 ) when to_char(b.pl_date,''D'') > 4 then (b.thu_pl ) else 0 end as thu_pl , case when to_char(b.pl_date,''D'') = 5 then (b.inception_pl *-1 + b.inception_premium_pl * -1) when to_char(b.pl_date,''D'') > 5 then (b.fri_pl) else 0 end as fri_pl ,
(b.mon_pl + b.tue_pl + b.wed_pl + b.thu_pl + b.fri_pl) + (b.inception_pl* -1 + b.inception_premium_pl * -1) as wtd_pl, case when b.wtd_premium_pl <> 0 then b.wtd_premium_pl + (b.inception_premium_pl * -1) else b.wtd_premium_pl end as wtd_premium_pl , case when b.mtd_pl <> 0 then b.mtd_pl + (b.inception_pl * -1) else b.mtd_pl end as mtd_pl ,
case when b.mtd_premium_pl <> 0 then b.mtd_premium_pl + (b.inception_premium_pl * -1) else b.mtd_premium_pl end as mtd_premium_pl, case when b.ytd_pl <> 0 then b.ytd_pl + (b.inception_pl * -1) else b.ytd_pl end as ytd_pl,
case when b.ytd_premium_pl <> 0 then b.ytd_premium_pl + (b.inception_premium_pl * -1) else b.ytd_premium_pl end as ytd_premium_pl ,
a.base_ccy as IN_STRIKECURR, a.quoted_ccy as IN_QUOTEDCUR, a.region_code as dlc_region,a.entity_acronym as dlc_entity, to_char(a.trade_id) as dtl_reference, 8 as trade_state,
case when to_char(b.pl_date,''D'') = 6 then b.pl_date + 2 else b.pl_date end as blankout_date
from tbl_trade_hist a
join tbl_pl b on a.trade_id = b.trade_id and a.version = b.trade_version
join tbl_trade_hist c on a.tradE_id = c.trade_id join tbl_pl d on c.trade_id = d.trade_id and c.version = d.trade_version and d.pl_date = (select max(e.pl_date) from tbl_pl e where c.trade_id = e.trade_id and e.pl_date <= c.amendment_date)
join tbl_bo_book f on a.bo_book_id = f.bo_book_id and f.business_area = ''OPTIONS''
where (b.bo_book_id <> d.bo_book_id or a.region_code <> c.region_code or a.entity_acronym <> c.entity_acronym or a.base_ccy <> c.base_ccy or a.quoted_ccy <> c.quoted_ccy)
and d.pl_date - b.pl_date = case when to_char(d.pl_date,''DAY'') = ''MON'' then 3 else 1 end and d.pl_date <= to_date( fv[EOD] ,''DD-MON-YYYY'') ))
group by xt_strategy,ACCT_DESCRIPTION,DLC_REGION,DLC_ENTITY';
c clob;
s varchar2(25000);
i numeric := 424;
begin
c := xml;
dbms_output.put_line('length of clob: ' || dbms_lob.getlength(c));
dbms_output.put_line('split clob at: ' || i);
dbms_output.put_line('desired substring length: ' || to_char(dbms_lob.getlength(c) - i));
s := dbms_lob.substr(c, dbms_lob.getlength(c) - i, i + 1);
dbms_output.put_line('length of substring: ' || length(s));
end;I checked for the database characterset and they are same - AL32UTF8
The result we get is
Output from MD1 database
length of clob: 10616
split clob at: 424
desired substring length: 10192
length of substring: 10192
Output from MD2 database
length of clob: 10616
split clob at: 424
desired substring length: 10192
length of substring: 8191Any idea why there is this discrepancy ?
Edited by: USER101 on Feb 19, 2010 4:24 PMThe EOF and the LF versus CR/LF could influence the count difference, yes.
Another explain could possibly be character set conversions. The BFILE I believe counts bytes, a CLOB would count "characters" - so if the source happens to contain a few multibyte characters (UTF), then the byte count would be larger than the character count.
To help you find the cause for your exact file, then I can suggest a couple of things you might do to explore the issue:
<li>Load the file into a BLOB instead of a CLOB and see what getlength() returns for the BLOB. BLOBs would also do byte counts and not try to treat the source as text.
<li>Save the CLOB back into the filesystem and compare the original file with the exported CLOB and check the differences with some filecompare tool. -
Performance diff between substr() and dbms_lob.substr()?
I have a ton of existing views that use dbms_lob.substr(MyClobColumn).
A developer recently noticed he got the same results with substr(MyClobColumn) - 10.1.0.3. Must have been added functionality on a patch/upgrade somewhere.
Is there a performance gain by dropping the "dbms_lob."?
KenFrom the manual.
The SUBSTR functions return a portion of string, beginning at character position, substring_length characters long. SUBSTR calculates lengths using characters as defined by the input character set. SUBSTRB uses bytes instead of characters. SUBSTRC uses Unicode complete characters. SUBSTR2 uses UCS2 code points. SUBSTR4 uses UCS4 code points.
If position is 0, then it is treated as 1.
If position is positive, then Oracle Database counts from the beginning of string to find the first character.
If position is negative, then Oracle counts backward from the end of string.
If substring_length is omitted, then Oracle returns all characters to the end of string. If substring_length is less than 1, then Oracle returns null.
string can be any of the datatypes CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. Both position and substring_length must be of datatype NUMBER, or any datatype that can be implicitly converted to NUMBER, and must resolve to an integer. The return value is the same datatype as string. Floating-point numbers passed as arguments to SUBSTR are automatically converted to integers. -
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,
MartinThe 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 -
Error while converting CLOB to varchar using DBMS_LOB.SUBSTR() in Oracle11g
Hi
Whenever I am using DBMS_LOB.SUBSTR(columnname,4000,1) package for a clob column in a simple Select Query, the following error is thrown for Oracle 11g version.
ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at line 1.
Please find the installation details of the database and the character set
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
PARAMETER VALUE
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CHARACTERSET AL32UTF8
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_RDBMS_VERSION 11.2.0.1.0
It is working fine if I reduce from 4000 to 3500 . But I want to use 4000.
Please let me know if any solutionyou are using a multibyte character set:
NLS_CHARACTERSET AL32UTF8
so each character takes between 1 and 4 bytes of storage.
a varchar2(4000) column can only hold 4000 BYTES. Regardless of the character set - varchar2 is limited to 4000 bytes.
In a single byte character set, that is 4000 characters as a character = a byte
In your character set, a varchar2(4000) can hold somewhere between 1000 and 4000 characters - depending on what the characters are.
So, you must have some CLOB whose first 4000 characters include at least one "more than one byte" character. That won't fit into a varchar2(4000)
Your approach of backing off the substr size is reasonable (and you'll need to remember that in your application - end users can type in as little as 1000 characters and get an error about the column being too small!) as it reduces the number of BYTES to be belong 4000. -
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 ( 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 -
DBMS_LOB.Substr Issues
Hello everyone,
I'm trying to use dbms_lob.substr on a clob column in one of my tables. I'm searching the table for a particular phrase, which should be the first two words in this column. Any row that has that phrase should be returned. However, when I run the script, I get only rows where the ONLY words in the entire column are the two words. Here's an example
| ID | | Name | | Information |
| 1 | | Jorge | | Terminated for negligence |
| 2 | | Stephanie | | Terminated for ... ? |
I need the script to return both of those rows.
Here's my script:
WHERE
dbms_loc.substr("EMPLOYEE"."COMMENTS", 15, 1)='Terminated for'
Thanks,
JoeNevermind, fixed it by adding a space to the end of the search string.
They really need a delete feature up here. -
When I run the following query to select the first 4001 characters from the CLOB field:
select dbms_lob.substr(field,4001,1)
from table
I get the following error:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
If I change it to 4000 or less it works fine.
Alan
nullHello,
It is possible that you have to use a select into statement and work further wit the result.
Here is an example I found in Oracle documentation :
PROCEDURE Example_14a IS
src_lob CLOB;
pos INTEGER := 2147483647;
buf VARCHAR2(32000);
BEGIN
SELECT c_lob INTO src_lob FROM lob_table
WHERE key_value = 21;
buf := DBMS_LOB.SUBSTR(src_lob, 32767, pos);
/* process the data */
END;
Hope this helps you.
Regards,
Cindy
null -
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. -
Parameters for substr and dbms_lob.substr
The syntax for substr in SQL functions and for the function in dbms_lob package is not matching and hence confusing for programmers. It will be less confusing if parameters for both functions are of the same order.
In Sql functions the the syntax for substr is substr(string, offset, amount)
In dbms_lob package the syntax for the substr function is dbms_lob.substr(lob_loc, amount, offset)
MohanI think he wants to send a suggestion to Oracle via this forum.
-
How to return Varchar2(1) from function ?? Simple but annoying :(
Hi,
I have a function something like...
CREATE OR REPLACE FUNCTION Test ( id number) RETURN VARCHAR2 ...
Now I am using this function in a View as ...
select
test(123) as Test
In the View description, this column appears as Varchar 4000. whereas I want it as varchar2(1).
When i redefine the function return value
CREATE OR REPLACE FUNCTION Test (id1 number) RETURN VARCHAR2(1) ...
It gives error...
Please suggest.
Thanks in Advance.SQL> CREATE OR REPLACE FUNCTION Test ( id number) RETURN VARCHAR2
2 as
3 begin
4 return 'A';
5 end;
6 /
Functie is aangemaakt.
SQL> create view v_test as select test(123) as test from dual
2 /
View is aangemaakt.
SQL> desc v_test
Naam Null? Type
TEST VARCHAR2(4000)
SQL> create or replace view v_test as select cast(test(123) as varchar2(1)) as test from dual
2 /
View is aangemaakt.
SQL> desc v_test
Naam Null? Type
TEST VARCHAR2(1)Regards,
Rob. -
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 -
Help. Strange problem with a function returning VARCHAR2
Hi.
i have a function that returns VARCHAR2, the following happens:
IS
v_retorno VARCHAR2(1000);
v_stm2 VARCHAR2(500);
v_stm1 VARCHAR2(500);
BEGIN
v_retorno :='INSERT INTO '||p_nome_tabela||'('||v_stm1||') VALUES('||v_stm2||')';
-- it raises an exception OTHERS here
v_stm1 has the value :
PERFIL,TIPDOC,GRPIMP,DES,IMPDES,GRPAGI,TOTAGI,TOTPOSRVP,TOTNEGRVP,TOTALIZA,TEMMSG,ORDEM,CODFORCAB,SINAL,ORDEM,CODEMP,USER_CRI,DT_CRI
v_stm2 has the value:
'BASE','03','999999','teste','N','0701','N','111111','222222','S','N',TO_NUMBER('111'),'X',TO_NUMBER('1'),TO_NUMBER('222'),TO_NUMBER('10'),'427195',TO_DATE('19-05-2008 04:32:49','DD-MM-YYYY HH:MI:SS')
p_nome_tabela is a table name, for example my_table.
This is to produce a varchar2 string to execute dynamic sql.
Can you help? I don't understand what's wrong.
If i do this :
v_retorno :='INSERT INTO '||p_nome_tabela||'('||v_stm1||') VALUES(';
it works, doesn't raise the OTHERS exception, but if i had the other variable, the OTHER is raised.No idea if this is relevant here or not, but:
v_retorno VARCHAR2(1000);
v_stm2 VARCHAR2(500);
v_stm1 VARCHAR2(500);What happens if your v_stm1 and v_stm2 variables are both 500 characters long?
I think you should think about increasing the length of v_retorno...
Maybe you are looking for
-
Drawing attention to an FP object DId YOU know this?
Often when we are walking a user through filling out some required information we want to direct their attention to a particular control. The traditional wasy of oing this is to use "key focus" and if more "help" is required maybe change a string con
-
How to install Archlinux use wingrub??
I once installed some linux distributions using wingrub. These just only need *.iso, initrd and vmlinuz 3 files. When reboot system use wingrub, use these commands to boot the installation: grub>kernel (hd0,0)/vmlinuz root=/dev/ram ramdisk_size=20000
-
hi how to make query cfl... i created combo box in system form..its have two type...job order, subcontracting... when i choose job order . its open production order list....when i choose subcontracting its open Purchase order list... Thanks & regards
-
Problem with job RDDEXECL (STMS)
Hi Coleagues The problems is that job RDDEXECL(Execution of programs for post - import processing) is canceled during execution. with the error: *What happened? Error in ABAP application program. The current ABAP program "SAPLPRGN_UTILITIES"
-
My Church website PDF files no longer showing text.
<i>Locking duplicate thread.<br>Please continue here: [[/questions/1037680]]</i> http://www.spfcp.org/bulletins.cfm November OK. December shows boxes, not text. Please let me know why I can't see the text. Their tech person said all is normal on thei