2016-03-30 4 views
0

pl/sqlプロシージャの引数として列名のcsvを渡していますが、これはsqlコマンドのby節で使用されますが無視されます。plsqlの引数として列を渡す

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; 

入力はありますか?

+0

"order by"というのは、test1の列です。あなたのデータがパラメータ名と説明の列で順序付けられると思われるのはなぜですか? 、この列でソートするには、パラメータ名で注文を含めるようにクエリを変更する必要があります。説明 – elirevach

答えて

2

あなたは静的カーソルを注文する変数を使用しているので、結果はあなたが動的カーソルの順序を変更するには、あなたの変数を使用する必要がある場合は、あなたが何かを必要とするかもしれない

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; 
+0

ありがとう!それは私の要件のために働く。 –