Question

What parameter changes the default length of dbms_lob.substr?

Asked by: geotiger

Here are my codes:

CREATE OR REPLACE PROCEDURE exec_now (
  s      CLOB,                     -- SQL statements
  p_lvl  INTEGER  DEFAULT 0        -- message level      
) IS
  v_prg  VARCHAR2(100) := 'exec_now';
  n      NUMBER;
  m      NUMBER;
  msg    VARCHAR2(200);

  PROCEDURE echo (
    msg clob,
    lvl NUMBER DEFAULT 999
  ) IS
  BEGIN
    IF lvl <= p_lvl THEN
        dbms_output.put_line(msg);
    END IF;
  END;

BEGIN
  n := dbms_lob.getlength(s);
  msg := 'INFO('||v_prg||'): '||TO_CHAR(n)||' characters.';
  echo(msg, 1);
  dbms_output.enable(1000000);
  IF n < 32767 THEN
      echo('INFO('||v_prg||'): executing codes (1)...', 1);
      m := LENGTH(DBMS_LOB.SUBSTR(s));
      -- echo(DBMS_LOB.SUBSTR(s), 1);
      msg := 'INFO('||v_prg||'): '||TO_CHAR(m)||'/'||TO_CHAR(n)||' characters.';
      echo(msg, 1);
      EXECUTE IMMEDIATE DBMS_LOB.SUBSTR(s);
      msg := 'INFO('||v_prg||'): OK!';
  ELSIF n < 64000 THEN
      echo('INFO('||v_prg||'): executing codes (2)...', 1);
      m := n - 32000;
      EXECUTE IMMEDIATE DBMS_LOB.SUBSTR(s, 32000, 1)||DBMS_LOB.SUBSTR(s, m, 32001);
      msg := 'INFO('||v_prg||'): OK!';
  ELSE
      msg := 'ERR('||v_prg||'): ';
      msg := msg||'skipped - too long('||TO_CHAR(n)||').';
  END IF;
  echo(msg,1);

  EXCEPTION  
  WHEN OTHERS THEN  
    echo('ERR('||v_prg||'): '||SQLERRM,0);
    raise;
END;
/  

show err

DECLARE
  s CLOB;
  s1   LONG;
  s2   LONG;
  n    NUMBER;
BEGIN
  dbms_lob.createtemporary(s, TRUE);
  dbms_lob.open(s, dbms_lob.lob_readwrite);
  s1 := 'BEGIN null; ' || LPAD (' ', 32000, ' ');
  n := length(s1||' END;'); dbms_lob.writeappend(s, n, s1||' END;');  
  exec_now(s,5);
  dbms_lob.close(s);

  dbms_lob.createtemporary(s, TRUE);
  dbms_lob.open(s, dbms_lob.lob_readwrite);
  -- n := dbms_lob.getlength(s); dbms_lob.erase(s, n, 1);
  n := length(s1);            dbms_lob.writeappend(s, n, s1);  
  s2 := RPAD (' ', 12000, ' ') || ' END;';
  n := length(s2); dbms_lob.writeappend(s, n, s2);    
  exec_now(s,5);
  dbms_lob.close(s);

END;
/

I used the above test code and got two different outputs:

in instance on Window 2003 server:
----------------------------------
INFO(exec_now): 32017 characters.
INFO(exec_now): executing codes (1)...
INFO(exec_now): 32017/32017 characters.
INFO(exec_now): Codes in was executed.
INFO(exec_now): 44017 characters.
INFO(exec_now): executing codes (2)...
INFO(exec_now): Codes was executed.

PL/SQL procedure successfully completed.

In instance on Solaris server
-------------------------------
INFO(exec_now): 32017 characters.
INFO(exec_now): executing codes (1)...
INFO(exec_now): 8191/32017 characters.
ERR(exec_now): ORA-06550: line 1, column 8191:
PLS-00103: Encountered the symbol
 "end-of-file" when expecting one of the following:

Q: What parameter sets the limit on what dbms_lob.substr returns? It is supposed to be 32k but it only returns 8k in one of the Oracle instances. Both instances are Oracle 10.2.0.3.





This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-04-04 at 12:46:48ID23297200
Topics

Oracle 10.x

,

PL / SQL

,

Sun Solaris

Participating Experts
1
Points
200
Comments
8

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. DBMS_SQL package problem
    create or replace PROCEDURE tester (str IN VARCHAR2) as v_cid INTEGER; rows_processed INTEGER; BEGIN v_cid := dbms_sql.open_cursor; dbms_sql.parse(v_cid, str, dbms_sql.v7); rows_processed := dbms_sql.execute(v_cid); dbms_sql.close_cursor(v_cid); EXCEPTION WHEN OTHERS THEN ...
  2. dbms_output.put_line line size
    Hello all, I am running under Oracle 8.0.5. on Windows NT. I have a package that uses dbms_output.put_line to build up a script. In the past I have had problems with the number of lines returned by the dbms_output (buffer overflow) which I rectified with ....exec dbms_outp...
  3. dbms_lob.writeappend(...)
    Hi! I have some troubles with the following stored procedure. in: i_message_id NUMBER in: i_message1 varchar2 in: i_message2 varchar2 ... in: i_message6 varchar2 This 6 strings should be in a clob. ... IS t_clob CLOB; BEGIN dbms_lob.createTemporary(t_clob, TRUE); dbms...
  4. DBMS_SQL.PARSE
    From documentations for the above, DBMS_SQL.PARSE ( c IN INTEGER, statement IN VARCHAR2, language_flag IN INTEGER); DBMS_SQL.PARSE ( c IN INTEGER, statement IN VARCHAR2S, lb IN INTE...
  5. DBMS_LOB package not found
    I am uable to find DBMS_LOB package in my databse. The o/p for the query: SELECT * FROM v$version is as given below Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production PL/SQL Release 8.1.7.0.0 - Production CORE 8.1.7.0.0 Production TNS for Solaris: Version 8.1...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: yuzhPosted on 2008-04-06 at 18:04:27ID: 21293784

For fixed-width n-byte CLOBs, if the input amount for SUBSTR is specified to be greater than (32767/n), then SUBSTR returns a character buffer of length (32767/n), or the length of the CLOB, whichever is lesser.

see the following doc for more details:
http://www.csee.umbc.edu/help/oracle8/server.815/a68001/dbms_lob.htm
also:
http://www.unix.org.ua/orelly/oracle/bipack/ch08_03.htm

 

by: geotigerPosted on 2008-04-07 at 08:08:09ID: 21297631

Yuzh,

Thanks for the info, but it does not answer my questions. I know the default is 32k. Why it only returns 8k in one of my Oracle instances? What parameter sets the limit how many characters SUBSTR returns?

Thanks,

GT

 

by: geotigerPosted on 2008-04-07 at 08:39:30ID: 21297954

This one might be easier to test on your Oracle instances since it does not create any object:

DECLARE
  s    CLOB;
  s1   LONG;
  s2   LONG;
  n    NUMBER;
  m    NUMBER;
BEGIN
  dbms_lob.createtemporary(s, TRUE);
  dbms_lob.open(s, dbms_lob.lob_readwrite);
  s1 := 'BEGIN null; ' || LPAD (' ', 32000, ' ')||' END;';
  n := length(s1); dbms_lob.writeappend(s, n, s1);  
  m := LENGTH(DBMS_LOB.SUBSTR(s));
  dbms_output.put_line('N='||TO_CHAR(n)||','||'M='||TO_CHAR(m));
  dbms_lob.close(s);
END;
/

I have run it on all of my Oracle instances and found out that it returns 8k on Solaris Oracle instances and 32k on Window Oracle instances in version 9.2.0.1, 9.2.0.8, 10.2.0.3.  Why? And how to make all returns 32k?

 

by: geotigerPosted on 2008-04-07 at 10:10:12ID: 21298735

OK, if you do not have answer to my questions, you will get some points to test the code above and report your results here. I just want make sure my finding is correct first, i.e., dbms_lob.substr returns different results from Oracle on Solaris then from Oracle on Windows.

 

by: yuzhPosted on 2008-04-07 at 18:28:10ID: 21301886

Can you do something like:
DBMS_LOB.SUBSTR(DATA,DBMS_LOB.GETLENGTH(DATA))
or
DBMS_LOB.SUBSTR(v_blob, v_chunk, v_offset),
 
instead of    DBMS_LOB.SUBSTR(s)                    

 

by: geotigerPosted on 2008-04-08 at 05:00:23ID: 21304268


I did that too. No difference - still returns 8191 characters. Have you tried on your systems?


m := LENGTH(DBMS_LOB.SUBSTR(s, 32000, 1));

 

by: geotigerPosted on 2008-05-05 at 07:03:28ID: 21500087

I got a word from Oracle. This is not a "bug", and it is just a feature if you uses multiple bit character set.

This happens for AL32UTF8.
From Oracle® Database PL/SQL Packages and Types Reference 10g Release 2 (10.2) Part Number B14258-01
"
SUBSTR Functions
This function returns amount bytes or characters of a LOB, starting from an absolute offset from the beginning of the LOB.
For fixed-width n-byte CLOBs, if the input amount for SUBSTR is greater than (32767/n), then SUBSTR
returns a character buffer of length (32767/n), or the length of the CLOB, whic
hever is lesser. For CLOBs in a varying-width character set, n is the maximum by
te-width used for characters in the CLOB."

 

by: geotigerPosted on 2008-05-05 at 07:04:06ID: 21500095

Here is the work around:
-- start workaround
create or replace function safe_clob_substr(
lob_loc IN CLOB ,
amount in number default 32767,
offset in number default 1) return varchar2
as
tmp_store varchar2(32767) := '';
tmp_amount number := amount;
tmp_offset number := offset;
begin
if tmp_amount > 8191 then
while tmp_amount > 8191 loop
tmp_store := tmp_store||
dbms_lob.substr(lob_loc, 8191 , tmp_offset);
tmp_amount := tmp_amount-8191;
tmp_offset := tmp_offset+8191;
end loop;
end if;
tmp_store := tmp_store||
dbms_lob.substr(lob_loc, tmp_amount , tmp_offset);
return tmp_store;
end safe_clob_substr;
/
-- end workaround

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...