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.
Similar Messages
-
Create Or Replace Function Error
Hello,
I'm doing text mining using Oracle SQL Developer: ODMiner.. I imported the data "WEBLOG" into a table.. This weblog data consist of users activity, date, time, url, etc. The first step I took was to use a function to transform date and time that I have in the data table, into a number representing the 40 mins since 01-01-1990. I did this by dividing it by 2400 (seconds in 40 mins). The main purpose is to have a time frame for the sessions.
I used the following code,
CREATE OR REPLACE FUNCTION ssnDate(
DATE IN VARCHAR2 DEFAULT 03-01-18,
TIME IN VARCHAR2
) RETURN NUMBER
AS
BEGIN
RETURN TRUNC((to_date(DATE||' '||TIME, 'DD-MM-YY HH:MM:SS')- to_date('01-JAN-1990','DD-MON-YYYY')) * (86400/2400);
END ssnDate;
This was what appeared in the log after running the statement,
FUNCTION ssnDate compiled
Warning: execution completed with warning
After this, I tried to create a VIEW to transform the DATE and TIME with the ssnDate that was created earlier on, and concatenate the CS_URI_STEM (which is the resource accessed), and CS_URI_QUERY (which is the the query, if any, the client was trying to perform)into a new field called WEB_LINK.
This is the code used,
CREATE OR REPLACE VIEW WEBLOG_VIEWS("C_IP", "WEB_LINK", "CS_USER_AGENT", "SESSION")
AS
SELECT ssnDate(LOG_DATE, LOG_TIME) AS 'SESSION',
C_IP,
CS_USER_AGENT,
(CS_URI_STEM||'?'||CS_URI_QUERY) AS WEB_LINK
FROM WEBLOG;
Now from this I got the following error..
Error starting at line 1 in command:
CREATE OR REPLACE VIEW WEBLOG_VIEWS("C_IP", "WEB_LINK", "CS_USER_AGENT", "SESSION")
AS
SELECT ssnDate(LOG_DATE, LOG_TIME) AS 'SESSION',
C_IP,
CS_USER_AGENT,
(CS_URI_STEM||'?'||CS_URI_QUERY) AS WEB_LINK
FROM WEBLOG
Error at Command Line:3 Column:38
Error report:
SQL Error: ORA-00923: FROM keyword not found where expected
00923. 00000 - "FROM keyword not found where expected"
*Cause:
*Action:
I don't get where I'm going wrong with this.. This is the data preparation stage which requires me to prep the data before applying modeling techniques or algorithms.. The next step would be grouping the data, based on the session time, ip and the user agent of each session along with the web_links fields visited by the user in that session.
I would really be grateful for any inputs on where I'm going wrong and any solutions for that!Ok, not sure I really understand, but I posted the query and this is the output I got..
ORA-31603: object "WEBLOG" of type TABLE not found in schema "WEBLOG_TABLE_OWNER_NAME"
ORA-06512: at "SYS.DBMS_METADATA", line 2625
ORA-06512: at "SYS.DBMS_METADATA", line 2668
ORA-06512: at "SYS.DBMS_METADATA", line 2983
ORA-06512: at "SYS.DBMS_METADATA", line 3897
ORA-06512: at "SYS.DBMS_METADATA", line 5678
ORA-06512: at line 1
31603. 00000 - "object \"%s\" of type %s not found in schema \"%s\""
*Cause: The specified object was not found in the database.
*Action: Correct the object specification and try the call again. -
I am little bit struggling to get the my sql function below, to execute the correct output:
ALTER FUNCTION [dbo].[ReplaceTags](@XML VARCHAR(MAX))
RETURNS VARCHAR(MAX)
AS
BEGIN
SELECT @XML = REPLACE(@XML,[Name],'<a href="<a href="pagename.aspx?tag='+[name]+'">'+[name]+'</a>')
FROM [dbo].[database_tags]
where UploadDate >= '2014-09-01'
RETURN @XML
END
When I call the function (select title, [dbo].[ReplaceTags](XML) from article ), it outputs the following result below, whereas the original data is this - (One is a 1m block of AIREM 2006-1X 2A3,).
Query output:
One is a &#163;1m block of <a href="<a href="pagename.aspx?tag=<a href="<a href="pagename.aspx?tag=<a href="<a href="pagename.aspx?tag=<a href="<a href="pagename.aspx?tag=<a href="<a
href="pagename.aspx?tag=AIREM 2006-1X 2A3">AIREM 2006-1X 2A3</a>"><a href="<a href="pagename.aspx?tag=AIREM 2006-1X 2A3">AIREM 2006-1X 2A3</a></a>"><a href="<a href="pagename.aspx?tag=<a
href="<a href="pagename.aspx?tag=AIREM 2006-1X 2A3">AIREM 2006-1X 2A3</a>"><a href="<a href="pagename.aspx?tag=AIREM 2006-1X 2A3">AIREM 2006-1X 2A3</a></a></a>"><a href="<a
href="pagename.aspx?tag=<a href="<a
I am not sure, why it keep duplicating the name. Please advice, where I may be going wrong.
Thank you for your help and time.Hi,
There is no problem do this using CLR in the database side, as well. You can use SQLCLR regular expression function.
In any case your HTML is wrong in the original question. You asked for
SELECT @XML = REPLACE(@XML,[Name],'<a href="<a href="pagename.aspx?tag='+[name]+'">'+[name]+'</a>')
but you need
SELECT @XML = REPLACE(@XML,[Name],'<a href="pagename.aspx?tag='+[name]+'">'+[name]+'</a>')
Please post DDL+DML for the [database_tags] table.
Ronen Ariely
[Personal Site] [Blog] [Facebook] -
Error using Replace funciton in java
hi, i need to replace my ' in sql string with '' so that no problem will occur when i execute the sql statement. i tried strName.replace('\'','\'\'') and recieved an error message when i compile, saying that i have unclosed character literal. anyone can tell me what's wrong? thanks...
the replace function will only replace one character.
It can not swap one character for two,
If you have Java 1.4 you can do a replaceAll() function
However, I would recommend you look at using prepared statements rather than escaping yourself manually. It is less error prone in the long run.
ie
Instead of
String sql = "Select * from person where name = '" + person.getName() + "'";
Statement stmt = connection.createStatement();
stmt.executeQuery(sql);
do
String sql = "Select * from person where name = ?";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, person.getName()); -
Bulk Replacements using Replace function in oracle 8i
Hi All,
Iam using oracle 8i version and i need to use Replace function for bulf replacements i mean i need to replace around 250 rows. So please anyone suggest me how to proceed
on this request as iam using oracle 8i version.
Thanks!
SriniWrite one update statement.
The where condition is the filter what rows need to be touched.
The SET condition will do the data change. For example it could use the REPLACE function if that is what it is needed.
One single update statement over 20 rows would mean the task is done in BULK. 20 single updates that each handle one row would mean it is row by row = slow by slow processing. -
Hi all
I'm trying to convert an xml document from one format to another format.I'm writing a stylesheet for this.I'm kind of new to XSLT.What I want is to replace a string with another only if exact match occurs for eg:
if i'm looking for the string "input" in the document it should replace only input variable in the following string but not "input_array".
<function_code>
y = input_array[0];
yp = 0;
time_previous = time_array[0];
result_array[0] = y;
for (int i = 1; i < channel_size; ++i) {
double input = input_array;
double time = time_array[i];
double h = time - time_previous;
double k = h/2.0;
double A = k*(omega_sq*input - 2*zeta*omega*yp - omega_sq*y); //k*calculate_ypp( time, y, yp, input );
double Beta = k*(yp + A/2.0);
double B = k*(omega_sq*input - 2*zeta*omega*(yp+A) - omega_sq*(y+Beta)); //B = k*calculate_ypp(time+k, y+Beta, yp+A, input);
double C = k*(omega_sq*input - 2*zeta*omega*(yp+B) - omega_sq*(y+Beta)); //C = k*calculate_ypp(time+k, y+Beta, yp+B, input);
result_array[i] = C;
} </function__code>
,the replace function XSLT provides replaces all occurrences of input i.e input followed by anything.Is there a way to do it??
thanks for your time and valuable inputs.
SreeHi
I wrote my own functions to check for the exact match and replace but i have another issue,since there is no variable reassignment in xslt how should i implement something like this
replace_code = replace_all_names(oldname,newname,replace_code);
where replace_code consists my code replaced and once any replacement occurs i have to pass it as an input for the next replacement.
thanks
Sree -
SQL replace function in JDeveloper
In SQL*Plus I run the following queries...
select last_name, phone_number from employees
LAST_NAME PHONE_NUMBER
Chung 650.505.1876
Dilly 650.505.2876
Gates 916.764.6600
select last_name, replace (phone_number, '.', '-') from employees
LAST_NAME REPLACE(PHONE_NUMBER
Chung 650-505-1876
Dilly 650-505-2876
Gates 916-764-6600
If I try to use the "REPLACE" function in the JDeveloper by editing the sql statement in the view object editor and run the page the results returned for the phone number column on the page are blank.
How can I substitute a dash for the period on the page?Try using AS:
select last_name, replace (phone_number, '.', '-') AS phone_number from employees
In this case is recommended for your VO a read only query. -
Replace() function doesn't work in Application Designer?
I'm using PeopleSoft Application Designer 8.51. I'm trying to do a simple Replace function so I can escape single quotes rather than allow them to blow up the sql query.
&deptid = Replace(&deptid, "'", "''");
App Designer chokes when I hit Save: "Invalid function parameter type. (2,19)"
According to the docs I'm using this correctly: http://docs.oracle.com/cd/E26239_01/pt851h3/eng/psbooks/tace/book.htm?File=tace/htm/tace14.htm#H4095
Even if I try to execute the example right out of the documentation, I get the same error: REPLACE("StringFun", "Fun", "Number");
Is this a bug in app designer? REPLACE is a super common thing, it's not something obscure. How can this not work?
Thanks in advance.I figured this out. “Replace” is a strange duck function that relies on offsets. “Substitute” is the magic I needed, works just like I was expecting Replace to work. The documentation I was reading on Replace was for “ PeopleSoft Analytic Calculation Engine” rather than peoplecode. I’ll pay closer attention to that next time. Maybe this will help someone else...
-
Hi,
I have a database in TT Release 7.0.3.1.0 and other in Release 11.2.2.4.0. I need use replace sql function over Release 7.0.3.1.0.
I know that it not apply in this version but I've tried with ttIsqlCS in node with TT11 through connection in database TT7 but I received this error:
ttIsqlCS database_test_R7
Command> select replace('asjkhdfkhaskdh','a','1') from dual;
2818: Unknown function REPLACE
The command failed.
Command> version;
TimesTen Release 11.2.2.4.0
Any idea ??
Thanks in advance.
Babs.Hi Babs,
I am afraid that you are out of luck. SQL is implemented in the TimesTen engine/libraries not in the ttIsql client. Since 7.0 SQL does not have th REPLACE() function there is no way to execute that in 7.0 regardless of the client you use. You'll need to find some other option to accomplish what you require (maybe upgrade the 7.0 database to 11.2.2?).
Chris -
Hi Guys,
I've been getting driven a little crazy with this piece of code...
create or replace function "GetHeirachy" (current VARCHAR2) return VARCHAR2 is
name VARCHAR2(4000);
hold VARCHAR2(4000);
parent VARCHAR2(4000);
BEGIN
LOOP
SELECT PARENT_ITEM_ID, ITEM_NAME INTO parent, name
FROM HTMLDB_OARS.ITEM_REGISTER
WHERE ITEM_ID = current;
IF hold IS NULL THEN
hold := name;
ELSE
hold := name || '/' || hold;
END IF;
current := parent;
EXIT WHEN current IS NULL;
END LOOP;
RETURN hold;
END "GetHeirachy";
basically the table structure is a self referencing table that creates a heirachy effect, and i need to be able to return a string of "parent/child/grandchild" for display purposes, the function begins with the grandchild and then uses the references to collect each parent and add it to the return.
When i put the function into sql workshop it is fine but if i try soemthing as simple as
begin
htp.prn(GetHeirachy('34'));
end;
i get these errors;
ORA-06550: line 2, column 9:
PLS-00905: object HTMLDB_OARS.GETHEIRACHY is invalid
ORA-06550: line 2, column 1:
PL/SQL: Statement ignored1. begin
2. htp.prn(GETHEIRACHY('34'));
3. end;
Is there something simple wrong with my function code? pl/sql isn't my native language... and i don't know how to debug properly!
Cheers,
Alexalright - code complete, i'll post it for the sake of others doing soemthing similar;
create or replace function GetHeirachy (current varchar2) return VARCHAR2 is
name VARCHAR2(4000);
hold VARCHAR2(4000);
parent VARCHAR2(4000);
cur VARCHAR2(4000);
BEGIN
cur := current;
for i in 1..10 LOOP
SELECT PARENT_ITEM_ID, ITEM_NAME INTO parent, name
FROM HTMLDB_OARS.ITEM_REGISTER
WHERE ITEM_ID = cur;
IF hold IS NULL THEN
hold := name;
ELSE
hold := name || '/' || hold;
END IF;
cur := parent;
EXIT WHEN cur IS NULL;
END LOOP;
RETURN hold;
END GetHeirachy;
:) - cheers for the help. -
Can I use Replace function in a decode??
Hello,
I am trying to use replace function inside a Decode Function,
Here is how I am doing it:
select
SUBSTR (
DECODE (
IH.DRVD_ALT_MAIL_ADDR_PRIM_FLAG,
'N',
REPLACE (
ih.subs_addr_1
|| ' '
|| ih.subs_addr_2
|| ' '
|| ih.subs_city
|| ','
|| ih.subs_state_code
|| ' '
|| ih.subs_zip_code,
'Y',
REPLACE (
IH.PRINT_ALT_MAIL_ADDR_LINE_1
|| ' '
|| IH.PRINT_ALT_MAIL_ADDR_LINE_2
|| ' '
|| IH.PRINT_ALT_MAIL_ADDR_LINE_3
|| ' '
|| IH.PRINT_ALT_MAIL_ADDR_LINE_4
|| ' '
|| IH.PRINT_ALT_MAIL_ADDR_LINE_5
|| ' '
|| IH.PRINT_ALT_MAIL_ADDR_LINE_6,
) 1,
50
address from x
Can anyone please tell me what am I doing wrong here, It always gives me an error about missing a right parenthesis.
Thanks in advance.Hi Jimmy,
Looks like you are missing the first comma in the SUBSTR function
SELECT SUBSTR (
DECODE (
ih.drvd_alt_mail_addr_prim_flag,
'N', REPLACE (
ih.subs_addr_1
|| ' '
|| ih.subs_addr_2
|| ' '
|| ih.subs_city
|| ','
|| ih.subs_state_code
|| ' '
|| ih.subs_zip_code,
'Y', REPLACE (
ih.print_alt_mail_addr_line_1
|| ' '
|| ih.print_alt_mail_addr_line_2
|| ' '
|| ih.print_alt_mail_addr_line_3
|| ' '
|| ih.print_alt_mail_addr_line_4
|| ' '
|| ih.print_alt_mail_addr_line_5
|| ' '
|| ih.print_alt_mail_addr_line_6,
), -- HERE
1,
50
address
FROM xRegards
Peter -
Replace function not working for XML CLOB data
Hi all,
I am generating XML using DBMS_XMLGEN in oracle 10g. After generating the XML, I am replacing the ROW tags with appropriate tag name using REPLACE function. Sometimes the tag name is not replaced correctly.
Eg.I am replacing </Cargo_ROW> with </CargoDetail>. But sometimes in one xml, this tag is coming as </CargoDetROW> or </CargoDetaiW>. The XML size is always huge and the same tag is repeated so many time in the loop and in the same XML, only one tag will be replaced incorrectly. This also not happening for all XMLs.
If any one knows the cause about this problem or solution, please share the same.
thanks,Yes Anton, you are right..
It was typecasting problem
replace supports clob
Check this out
SQL> declare
2 xmldata clob;
3 Begin
4 xmldata:='<Message transaction_log_id="" extraction_date="25/11/09 09:52:03 AM" versio
5 <Transaction>
6 <TransactionType>ORIGINAL</TransactionType>
7 <ControlNumber>60022449779</ControlNumber>
8 <BookingHeader>
9 <PortCodeOriginal>GBSOU</PortCodeOriginal>
10 <Contact>.</Contact>
11 <PhoneContact>.</PhoneContact>
12 </BookingHeader>
13 <PartyInformation>
14 <PartyDetails>
15 <PartyId>10002866</PartyId>
16 <Type>SHIP</Type>
17 <Name1>L LTD.</Name1>
18 </PartyDetails>
19 </PartyInformation>
20 <Cargo>
21 <CargoDetROW>
22 <CargoHeader>
23 <CargoReceivedSeqNo>600015391790</CargoReceivedSeqNo>
24 <CargoId>RW9330P013948</CargoId>
25 </CargoHeader>
26 <CargoDimensions>
27 <Length>1</Length>
28 <Width>2</Width>
29 </CargoDimensions>
30 </CargoDetail>
31 <CargoDetROW>
32 <CargoHeader>
33 <CargoReceivedSeqNo>600015391791</CargoReceivedSeqNo>
34 <CargoId>RW9330P01394AA</CargoId>
35 </CargoHeader>
36 <CargoDimensions>
37 <Length>2</Length>
38 <Width>2</Width>
39 </CargoDimensions>
40 </CargoDetail>
41 <Cargo_ROW>
42 <CargoHeader>
43 <CargoReceivedSeqNo>600015391792</CargoReceivedSeqNo>
44 <CargoId>RW9330P01322</CargoId>
45 </CargoDetaiW>
46 <CargoDimensions>
47 <Length>1</Length>
48 <Width>2</Width>
49 </CargoDimensions>
50 </Cargo_ROW>
51 </Cargo>
52 </Transaction>
53 </Message>';
54 xmldata:=to_clob(regexp_replac(xmldata,'</Cargo_ROW>|</CargoDetaiW>|</CargoDetROW>','</CargoDetail'));
55 xmldata:=to_clob(regexp_replace(xmldata,'<Cargo_ROW>|<CargoDetaiW>|<CargoDetROW>','<CargoDetail>'));
56 dbms_output.put_line(xmldata);
57 end;
58 /
<Message transaction_log_id="" extraction_date="25/11/09 09:52:03 AM"
version="1.0">
<Transaction>
<TransactionType>ORIGINAL</TransactionType>
<Contro
lNumber>60022449779</ControlNumber>
<BookingHeader>
<PortCodeOriginal>GBSOU</Por
tCodeOriginal>
<Contact>.</Contact>
<PhoneContact>.</PhoneContact>
</BookingHead
er>
<PartyInformation>
<PartyDetails>
<PartyId>10002866</PartyId>
<Type>SHIP</Ty
pe>
<Name1>L
LTD.</Name1>
</PartyDetails>
</PartyInformation>
<Cargo>
<CargoDetail>
<CargoHea
der>
<CargoReceivedSeqNo>600015391790</CargoReceivedSeqNo>
<CargoId>RW9330P01394
8</CargoId>
</CargoHeader>
<CargoDimensions>
<Length>1</Length>
<Width>2</Width>
</CargoDimensions>
</CargoDetail>
<CargoDetail>
<CargoHeader>
<CargoReceivedSeq
No>600015391791</CargoReceivedSeqNo>
<CargoId>RW9330P01394AA</CargoId>
</CargoHe
ader>
<CargoDimensions>
<Length>2</Length>
<Width>2</Width>
</CargoDimensions>
<
/CargoDetail>
<CargoDetail>
<CargoHeader>
<CargoReceivedSeqNo>600015391792</Carg
oReceivedSeqNo>
<CargoId>RW9330P01322</CargoId>
</CargoDetail>
<CargoDimensions>
<Length>1</Length>
<Width>2</Width>
</CargoDimensions>
</CargoDetail>
</Cargo>
</Transaction>
</Message>
PL/SQL procedure successfully completed.
SQL> Twinkle
Edited by: Twinkle on Nov 26, 2009 6:05 PM -
Prolem in CLOB replace function
Hi,
I am working on Oracle 10g (release 2).
Currently facing problem in replace function
My given patterns are
Replace(+string+, varchar2, clob)
Replace(+String+, clob, clob)
In both casese, I'm getting ORA-22828 error.
Can anyone please suggest the solution.
Thanks.Please see
http://asktom.oracle.com/pls/asktom/f?p=100:11:3388795154384573::::P11_QUESTION_ID:1533006062995 -
REPLACE function in PSP for formatting
Hi everyone,
<p>I am coding PL/SQL server pages at the moment and am trying to produce an onscreen report.
<br>I was just wondering if it is possible to use the REPLACE function to replace a part of a string with the same thing but in bold?
for example, I have tried:
<p>
htp.p('<TD WIDTH="43%" valign="top" align="left">'||REPLACE(var_comments,'''TEST''',||'<b>TEST</b>'||')'||'</TD>'); <p>but it isn't working. I just wanted to check it was possible and if so, where am I going wrong??
<p>
Thanks in advance!This will work:
htp.p('<TD WIDTH="43%" valign="top" align="left">'||REPLACE(var_comments,'''TEST''',||'<b>TEST</b>'||')'||'</TD>');I also suggest generating your table HTML using the htp.table... procedures. -
Replace function - special characters
Hi All,
If my column is encountering special characters I would like to replace with blank. Special characters may vary from record to record. Sometimes it is @ sometimes $,!,,$,^,<,&,<,>,?,",{,},+,_,),(.
Do we have any function same like replace that can replace all special characters, whatever it encounters with required value?
- please mark correct answersTake a look at this article
T-SQL:
How to Find Rows with Bad Characters
and check See Also section in that article for more articles on that topic.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles
Thanks Naomi
- please mark correct answers
Maybe you are looking for
-
My iPod touch isn't recognized by iTunes, but it is recognized by Windows.
I'm using Windows 8 and it worked okay for a while. I have uninstalled and re-installed iTunes without success. It works fine on my other computer (desktop Windows 7). Thanks for any suggestions Jim McColl
-
Hide Link Button Image used in Crystal Report 2008 while printing
Hello Experts, I am using Link Button of SAP B1 in Crystal Report 2008 which works perfectly. But when i am trying to export it, i am also getting the image of Link Button. Is there a way to hide the image while printing? Thanks Shiv
-
32 bit EHp1 system export error on Oracle 10.2.0.2 & windows
Hi All, I am performing export of solman EHp1 system base on Oracle 10.2.0.2 & windows 2003(32 bit) bot database & OS). Database size is 100 gig.during export it stope at error. I checked sapinst.log which shows below error INFO[E] 2010-09-16 21:03:2
-
How do I free up space on an I-phone 4 to allow a downlaod of IOS 7
Just tried to update my I-Phone 4 to IOS 7 and was told I didn't have enough space to do so. How do I free up space to allow the upgrade? I could free up 5.6 GB by deleting photos which are already saved in I-Cloud. How do I do that?
-
Missing Create, Delte and Open buttons in Portal - RM 3.0
Hi All, We are currently facing an odd issue in our Risk Management 3.0 frontend system (EP). In several screens u201Ccreateu201D, u201Cdeleteu201D and u201COpenu201D buttons are missing. All missing buttons appear when we click on the refresh button