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

Similar Messages

  • 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.

  • SQL Replace function: errors if replacement text is 8191 characters

    Oracle 10.2.0.3.0 Enterprise Edition
    I'm working on an application which has a function to generate emails.
    We have a template, which gets filled with data from the database depending on the email being sent.
    To do this I'm using the Replace function to replace certain parts of the template with the right data.
    It seems that if the replacement text (the third argument to the function) is longer than 8191 bytes the function throws a PL/SQL: numeric or value error.
    This limitation doesn't appear to be documented anywhere, certainly nowhere that I can find.
    Anyone know of a way around this short of building my own replace function?

    I've figured out what was going on.
    The database column for the replacement text is defined as a clob, but there is a front end limit of 10,000 characters for the field being used.
    When using the replace function I was assigning the value to a varchar2(32767) field in the PL/SQL.
    So in terms of datatypes the function call is:
    varchar2 := replace(varchar2, varchar2, clob)
    If the length of the clob is over 8191 characters it errors.
    (Presumably because of the bug mentioned in this thread DBMS_LOB.SUBSTR() returning 8191 characters instead of 32767
    I've fixed it by simply changing the datatype of the variable to which the value is being assigned to a clob.

  • 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 1

    Hello
    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

  • 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 PM

    The 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."?
    Ken

    From 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.

  • 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,
    Shine

    Hi.
    >
    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

    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
    null

    Hello,
    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

  • Why oracle function return 4000 characters ?

    Dear All
    When I write any function to get some return value in a query, its width is set to 4000. Moreover, when i write the same query to create any LOV, it gives an error that record group field cannot be greater than 2000. Where the actual width of this field is 200 characters.
    Why function always returns 4000 characters?
    Regards
    Edited by: OraLearner on Dec 1, 2010 11:47 AM

    Because the maximum of a varchar2 in SQL is 4000 and you have no dimension in your function:
    SQL> r
      1  create or replace function myfunc(inMaxVal in number) return varchar2 is
      2    vRet varchar2(32000);
      3  begin
      4    for i in 1..inMaxVal loop
      5      vRet := vRet || '1';
      6    end loop;
      7    return vRet;
      8* end;
    Function created.
    SQL> select myfunc(4001) from dual;
    select myfunc(4001) from dual
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at "SCOTT.MYFUNC", line 7
    SQL> select myfunc(4000) from dual;
    MYFUNC(4000)
    1111111111111111111111111111111111111111111111111111
    1111111111111111111111111111111111111111111111111111so the SQL Engine have to assume your function returns 4000 bytes. If you use this function in PL/SQL it can be up to 32767 bytes:
    SQL> r
      1  begin
      2  dbms_output.put_line(substr(myfunc(4002), 1,255));
      3* end;
    11111111111111111111111111111111111111111111111111111111
    PL/SQL procedure successfully completed.cheers

  • 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 solution

    you 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.

  • 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,
    Joe

    Nevermind, fixed it by adding a space to the end of the search string.
    They really need a delete feature up here.

  • 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

  • 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,
    Venkat

    DBMS_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.

  • Problem with wwsbr_api.modify_item and Text 8191 characters

    Hi all.
    I have a PL/SQL portlet used to insert/update content in Oracle Portal.
    I noticed that if I try to insert or update a text item with data longer than 8191 characters it gives the following error: ORA-06502: PL/SQL: numeric or value error. Also note that if I print the content right before the modify_item I get the full text entered by the user.
    Needless to say, if I try the same operation using the Portal wizard it works.
    I see the same error on both Portal 10.1.2.0.2 and Portal 9.0.4.1.0.
    Is this a known issue? Any workarounds?
    Thanks.
    Alessandro

    Anyone?
    Alessandro

Maybe you are looking for

  • Problem with AppActionListener

    Hi i am new to the JSF technology and i have faced a problem on my AppActionListener. I am currently using the java studio enterprise 8 plattform, jdk 1.5.0 application server 8.1 UR2 and the jsf 1.1 reference implementation. The problem is that it g

  • Flash Player 11 on Internet Explorer 6 ?

    Hello, I cannot install Flash Player 11 in IE6, a big part of our user base are unfortunately still on IE6 and our products targets Flash Player 11. What can we do about it without dumbing down our app? Thank you in advance

  • Memory Options for Manifest?

    Hi all, Is there a way to set the JVM memory arguments (like -Xms and -Xmx) in the manifest or similar mechanism? I'm converting an application from being launched with a .bat file to a double-clickable .jar, but i'm seeing a bit performance hit rega

  • CS5 launch problem -  moved to Australia from GB

    CS5 launch problem - moved to Australia from Uk/GB, bought a new lap top in Australia and Photoshop will not open even though it's downloaded and Bridge etc works on new machine - Problem error message... Exit Code: 7 --------------------------------

  • Show Content and Stacked canvas?

    Hello to all, I have a very simple form: - 1 datablock - 1 window - 2 canvas: the main (content) and a stacked one with all the items. - I want to have a multirecord view. As I have lots of items... and I need to show all of them in a specific format