2017-06-23 3 views
0

このsprocを使用して、取得するレコードの数を決定します。 それは次のようになります。私はそれが何をしたいのかOracle SPROCでTOPパラメータを無視する0

procedure ReadStockToSync(P_CUR out sys_refcursor, P_TAKE integer) is 

begin 

     open P_CUR for 
       select TOP (@P_TAKE) 

P_Takeが0 ある場合TOPを無視することは、私はそれを行うことができますどのように誰もが知っていますか?私があなただったら、私は2つのSQL文を持っており、パラメータに基づいて出力するかを決めるだろう

+3

オラクルには 'TOP'はありません。 PL/SQLでは変数の先頭に '@ 'が付きません –

答えて

1

、例えば:

procedure readstocktosync (p_take in integer, 
          p_cur out sys_refcursor) is 
begin 
    if p_take = 0 then 
    open p_cur for <your select query returning all rows>; 
    else 
    open p_cur for <your select query with the correct syntax to retrieve the "top" row(s)>; 
    end if; 
end readstocktosync; 
関連する問題