aspose file tools*
The moose likes Oracle/OAS and the fly likes Error in Oracle like clause Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "Error in Oracle like clause" Watch "Error in Oracle like clause" New topic
Author

Error in Oracle like clause

Preethinj Math
Greenhorn

Joined: Mar 07, 2006
Posts: 10
Hi,

Need help!

Here the like clause is not working,since the sql is itself in sinle quotes.
I don't know how to make the like clause work.
The error it is giving me is:

ORA-00920: invalid relational operator
ORA-06512: at "TABCOUNT", line 10
ORA-06512: at line 2


The code is
CREATE OR REPLACE FUNCTION tabcount (
tab IN VARCHAR2, field IN VARCHAR2 ,whr IN VARCHAR2)

RETURN INTEGER
IS
retval INTEGER;
BEGIN
DBMS_OUTPUT.PUT_LINE ('whr' ||whr);
DBMS_OUTPUT.PUT_LINE ('field1' ||field);
EXECUTE IMMEDIATE
' SELECT COUNT(*) FROM ' || tab ||
' WHERE ' || field || 'like ''%'||whr ||'%'''
INTO retval;
DBMS_OUTPUT.PUT_LINE ('countis!' ||retVal);

RETURN retval;
END tabcount;
/

Looking for some answer.

Thanks
Shital Supase
Greenhorn

Joined: Jun 05, 2006
Posts: 17
shital580@rediffmail.com

Hello preethinj,

the bug in ur query is the statement whatever u have written as || 'like ''%'||whr ||'%'''

should b

|| ' like ''%'||whr ||'%'''

u have skipped the blank space between the field values & like keyword
 
Don't get me started about those stupid light bulbs.
 
subject: Error in Oracle like clause