我想在下面执行pl sql查询并获得比较的结果。
EXECUTE IMMEDIATE 'select 5<6 FROM DUAL' ;
执行错误如下:
ORA-06550: line 1, column 18:
PLS-00103: Encountered the symbol "select 5<6 FROM DUAL" when expecting one of the following:
:= . ( @ % ;
The symbol ":=" was substituted for "select 5<6 FROM DUAL" to continue.
06550. 00000 - "line %s, column %s:n%s"
*Cause: Usually a PL/SQL compilation error.
*Action
:
我的两个数字之间的数学运算符是动态的,这意味着它可以是任何其他运算符,如<,比;, <=,>=, =等。它来自于我的存储过程的参数
举例:在我的SP中有3个参数
number1, number2和数学运算符。
实际上我在寻找的是javascript中的eval()函数,它会自动执行字符串操作并返回结果。Eval("5 & lt; 3,)
这里有一个选项:
SQL> set serveroutput on
SQL> declare
2 retval varchar2(20);
3 begin
4 execute immediate q'[select case when 5 < 6 then 'true'
5 else 'false'
6 end
7 from dual]'
8 into retval;
9
10 dbms_output.put_Line('Result: ' || retval);
11 end;
12 /
Result: true
PL/SQL procedure successfully completed.
SQL>
这是我的工作代码示例。
execute immediate 'select case when ' || SQL1R || item.operator|| SQL2R || ' then 1 else 0 end from dual' INTO COMP;
感谢@Littlefoot