Oracle 将列的顺序作为参数传递给pl sql
我将列名的csv作为pl/sql过程的参数传递,该过程将在sql命令的order by子句中使用,但它被忽略Oracle 将列的顺序作为参数传递给pl sql,oracle,plsql,sql-order-by,Oracle,Plsql,Sql Order By,我将列名的csv作为pl/sql过程的参数传递,该过程将在sql命令的order by子句中使用,但它被忽略 SET serverOutput ON SIZE unlimited; SET linesize 32767; declare test1 varchar2(30); begin test1 := 'PARAMETER_NAME,DESCRIPTION'; -- This will be passed as input parameter for rCursor in (select
SET serverOutput ON SIZE unlimited;
SET linesize 32767;
declare
test1 varchar2(30);
begin
test1 := 'PARAMETER_NAME,DESCRIPTION'; -- This will be passed as input parameter
for rCursor in (select * from configurations order by test1 asc) loop
dbms_output.put_line(rCursor.parameter_name || '-=-' || rCursor.Description);
-- Output is not ordered by any of these columns
end loop;
end;
任何输入?您正在使用一个变量对静态光标进行排序,因此结果将与
select * from configurations order by 'PARAMETER_NAME,DESCRIPTION'
如果需要使用变量动态更改光标的顺序,则可能需要类似以下内容:
declare
test1 varchar2(30);
rcursor SYS_REFCURSOR; /* define a cursor */
vConfiguration configurations%ROWTYPE; /* define a variable to host the result of your query */
begin
test1 := 'PARAMETER_NAME,DESCRIPTION'; -- This will be passed as input parameter
open rCursor for 'select * from configurations order by ' || test1; /* open a dynamic cursor */
loop
fetch rCursor into vConfiguration; /* fetch the cursor into a variable */
exit when rCursor%NOTFOUND; /* check if the cursor has rows */
dbms_output.put_line(vConfiguration.parameter_name || '-=-' || vConfiguration.Description);
end loop;
end;
您的查询“order by”是按test1列进行的,为什么您倾向于相信您的数据将按参数名称和描述列进行排序,要按此列进行排序,您需要将查询更改为包括按参数名称、描述排序