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.
Similar Messages
-
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 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
RobertAt 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. -
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.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. -
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. -
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 -
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.
-
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 -
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 -
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 -
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 -
Hi All,
I've got XSLT issue.
Suppose in XML I have string like that :
world.country.town.Moskow.SomeOtherValue
Capitalized word/s/ is/are/ always at the end.
Using XSLT how to get substring returning capitalized words only i.e Moskow.SomeOtherValue
ThanksHi,
Here are two possible solutions :
1) If you can run XSLT 2.0, then you may use a regular expression :
Sample XML :
<test>world.country.town.Moskow.SomeOtherValue</test>
<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:analyze-string select="test" regex="\.([A-Z].*)$">
<xsl:matching-substring>
<result><xsl:value-of select="regex-group(1)"/></result>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
output :
<result>Moskow.SomeOtherValue</result>2) With XSLT 1.0, you can use a recursive template to analyze the string :
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
<result>
<xsl:call-template name="find_cap_words">
<xsl:with-param name="in" select="test"/>
</xsl:call-template>
</result>
</xsl:template>
<xsl:template name="find_cap_words">
<xsl:param name="in"/>
<xsl:variable name="rem" select="substring-after($in,'.')"/>
<xsl:choose>
<xsl:when test="translate(substring($rem,1,1),'_ABCDEFGHIJKLMNOPQRSTUVWXYZ','_')=''">
<xsl:value-of select="$rem"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="find_cap_words">
<xsl:with-param name="in" select="$rem"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
output :
<result>Moskow.SomeOtherValue</result>Hope that helps. -
hi, i am learning java in class for school, and in my project i have one issue with the .substring method of strings.
my code is
import java.util.Scanner;
public class Valid
private String lastName;
private String email;
private boolean oneSymbol;
private boolean nonBlankLeft;
private boolean onePeriod;
private boolean nonBlankBoth;
Valid()
public void readData(Scanner input)
lastName = input.next();
email = input.next();
public void checkSymbol()
String s = email.substring(0);
int count = 0;
int x;
x = s.indexOf('@');
while (!(x == -1))
s = s.substring(0,x) = s.substring(x+1);
count++;
x = s.indexOf('@');
if (count == 1)
oneSymbol = true;
else
oneSymbol = false;
public void checkNonBlankLeft()
int x = email.indexOf(" @");
if (x == -1)
nonBlankLeft = true;
else
nonBlankLeft = false;
public void checkOnePeriod()
String s = email.substring(0);
int count = 0;
int x;
x = s.indexOf('.');
while (!(x == -1))
s = s.substring(0,x) = s.substring(x+1);
count++;
x = s.indexOf('.');
if (count >= 1)
onePeriod = true;
else
onePeriod = false;
public void checkNonBlank()
int x = email.indexOf(" . ");
if (x == -1)
nonBlankBoth = true;
else
nonBlankBoth = false;
public void writeResults(java.io.PrintWriter outputValid, java.io.PrintWriter outputInvalid)
if (oneSymbol && nonBlankLeft && onePeriod && nonBlankBoth)
outputValid.printf("%-15s%-30s", lastName, email + "\n");
else
outputInvalid.printf("%-15s%-30s", lastName, email + "\n");
if (oneSymbol == false)
outputInvalid.printf("%45s%-30s", " ", "@ symbol must occur once\n");
if (nonBlankLeft == false)
outputInvalid.printf("%45s%-30s", " ", "Must be a character before the @ symbol\n");
if (onePeriod == false)
outputInvalid.printf("%45s%-30s", " ", "Must contain one . (period)\n");
if (nonBlankBoth == false)
outputInvalid.printf("%45s%-30s", " ", "Both sides of . must be contain a character\n");
} i have issues with both .substring methods and i get these errors.
.\Valid.java:31: unexpected type
required: variable
found : value
s = s.substring(0,x) = s.substring(x+1);
^
.\Valid.java:58: unexpected type
required: variable
found : value
s = s.substring(0,x) = s.substring(x+1);
^
2 errorsgeorgemc wrote:
boulbrokdrm wrote:
thank you, you just showed me that i am a complete idiot lol
i ment to use + instead of =, just forgot to press the shift key i guess, but it should work now, thank youLol, easiest 10 dukes I ever made.If you made them why are they still just sitting there waiting to be awarded?
Hint, hint - OP, YOU NEED TO AWARD THEM
Maybe you are looking for
-
SAP dispatcher status is stopped in Console how can i start it
Hi All Help me out *SAP dispatcher status is stopped in Console how can i start it Dispatcher turns green to yellow suddenly and status changes to stopped and all WP elemets shows status as ended. Alert from Syslog : SAP Basis System: Message server
-
Task Outcome Field - Crawled Property not created
Hi, SharePoint is not creating crawled property for the OOB Task Outcome field... Is this by design or is it possible to include this field in search.. Regards, Muthukumar
-
How to create a sitemap for Apple Wiki server?
Since the content of a Wiki server is very dynamic, can the server generate a site map automatically? If I manually created a sitemap, where should I put it so that it will show up in the root of my site?
-
Pomodzen: a tiny pomodoro timer for dzen2
what's up, party people? if you're a cool cat, you know that pomodoros are the hottest way to ward off distractions and get stuff done. if you're not down with pomodoros yet, let me clue you in: wikipedia wrote: There are five basic steps to implemen
-
SHUTDOWN PROCESS IS TAKING TIME
Dear Collegue, What could be the issue while shutdown the database in Oracle 10g? It takes more than half-an-hour to shutdown. Regards, Purvesh Prajapati