Java 如何在传递的参数等于列的情况下订购oracle select
我在oracle中有一个函数,其返回值为sys\u refcursor,该函数为select打开。我正在将参数传递给这个oracle函数,我将使用与此参数相等的列对select进行排序。在示例中,我的select中有10列,并且我的参数可能与它们中的每一列相等。一个条件是像这样编写10 if子句Java 如何在传递的参数等于列的情况下订购oracle select,java,oracle,Java,Oracle,我在oracle中有一个函数,其返回值为sys\u refcursor,该函数为select打开。我正在将参数传递给这个oracle函数,我将使用与此参数相等的列对select进行排序。在示例中,我的select中有10列,并且我的参数可能与它们中的每一列相等。一个条件是像这样编写10 if子句 if myParam = 'name' then select <selected rows> from table a order by a.name end if; 如果myPar
if myParam = 'name' then
select <selected rows>
from table a
order by a.name
end if;
如果myParam='name',则
挑选
从表a
点名
如果结束;
我的代码是否还有其他条件需要更短的时间 使用:
CREATE OR REPLACE FUNCTION my_fun( ord VARCHAR2 )
RETURN sys_refcursor
IS
refcur SYS_REFCURSOR;
BEGIN
OPEN refcur FOR
'SELECT level as x, 100-level as y FROM dual
CONNECT BY LEVEL <= 10
ORDER BY ' || ord;
RETURN refcur;
END;
/
VAR x REFCURSOR;
exec :x := my_fun( 'x' );
print :x;
X Y
---------- ----------
1 99
2 98
3 97
4 96
5 95
6 94
7 93
8 92
9 91
10 90
10 rows selected.
exec :x := my_fun( 'y' );
print :x;
X Y
---------- ----------
10 90
9 91
8 92
7 93
6 94
5 95
4 96
3 97
2 98
1 99
10 rows selected.
exec :x := my_fun( 'z' );
print :x;
ORA-00904: "Z": invalid identifier
ORA-06512: "TEST.MY_FUN", line 7
ORA-06512: line 1
00904. 00000 - "%s: invalid identifier"