Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ORA-00920: invalid relational operator

Posted on 2009-07-06
5
Medium Priority
?
976 Views
Last Modified: 2012-05-07



function getFormattedString(f_inputString varchar2,
                            f_param       varchar2) return varchar2 is
  v_result             varchar2(8000);
  v_cnt                number := 1;
  v_Array eact_reports.t_array;
begin

  v_Array := Eact_Reports.split(f_inputString, ',');

  WHILE v_cnt <= v_Array.COUNT LOOP
    v_result := v_result || '''' || v_Array(v_cnt) || '''' || ',';
    v_cnt    := v_cnt + 1;
  end loop;

  if v_result is not null then
    v_result := f_param || ' IN (' ||
                substr(v_result, 0, length(v_result) - 1) || ')';
  else
    v_result := f_param ||' like  ''%''';
  end if;
  return v_result;
end getFormattedString;

select *  from EMP
where
    EXAMPLE_PACKAGE.getFormattedString(A,B,C,EMP.CODE)


I have written above function in a package.
i am calling this function in the where condition;but i am expecting the query should be formatted like this;

select *  from table
where
EMP.CODE IN('A','B','C')

but i am getting  below expection

ORA-00920: invalid relational operator
0
Comment
Question by:chaitu chaitu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24786698
>where     EXAMPLE_PACKAGE.getFormattedString(A,B,C,EMP.CODE)
that won't work, as it will interprete like this:

WHERE ' EMP.CODE IN(''A'',''B'',''C'') '
aka, a single string value. it cannot know you want to evaluate that "string" as part of the sql itself.

you will need dynamic sql. however, with SELECT, this will be tricky.
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 24786754
actually we have written a view for this query.

how to write dynamic sql for this or any other solution?
0
 
LVL 48

Accepted Solution

by:
schwertner earned 1500 total points
ID: 24787010
Functions deliver one value and could be written in SQL.

But

select *  from EMP
where
    EXAMPLE_PACKAGE.getFormattedString(A,B,C,EMP.CODE)

delivers ONE value let us say 10

Then

select *  from EMP
where
    10

has no meaning

Possible

select *  from EMP
where
    ammount < EXAMPLE_PACKAGE.getFormattedString(A,B,C,EMP.CODE)

is more meaningfull

Its is like

select *  from EMP
where
    ammount < 10




0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 24792502
function getFormattedString(f_inputString varchar2,f_delim varchar2) return varchar2
  is
  v_result varchar2(8000) ;
  v_cnt number:=1;
  v_Array eact_reports.t_array ;
  begin
   
             
                v_Array := Eact_Reports.split(f_inputString , f_delim);
   
                WHILE v_cnt <= v_Array.COUNT LOOP
                v_result := v_result || '''' || v_Array(v_cnt) || '''' || ',';
                v_cnt :=v_cnt+1;
                end loop;
     if v_result is not null then
                            v_result  := ''|| ' ('||substr(v_result ,1,length(v_result)-1 )||')';
                            else
                            v_result :=' LIKE ''%'' ';
                end if;        
  return v_result;
  end ;
END tax_report_package;

I have changed like this but still records r not coming.

select *  from table
where
AND EMP.CODE IN (SELECT EXAMPLE_PACKAGE.getFormattedString('A$B$C','$') FROM DUAL);
0
 
LVL 48

Expert Comment

by:schwertner
ID: 24792861
This is correct and it should formally work.
Investigate the values and their type.
The function returns one value of type varchar2.
What is the type of EMP.CODE?
If it is number use conversion TO_NUMBER or TO_CHAR.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question