2012-12-16 60 views

回答

6

測試上的Oracle 10g。

DECLARE 
    cur SYS_REFCURSOR; 
    vQuery VARCHAR2(32000) := 'SELECT COALESCE(:NULLS) FROM dual'; 
    vNulls VARCHAR2(32000) := '1, 1'; 
    i PLS_INTEGER := 2; 
BEGIN 
    LOOP 
     OPEN cur FOR REPLACE (vQuery, ':NULLS', vNulls); 
     CLOSE cur; 

     i := i + 1; 
     vNulls := vNulls || ', 1'; 
    END LOOP; 
    EXCEPTION 
     WHEN OTHERS THEN 
      DBMS_OUTPUT.PUT_LINE(i || ' ' || SQLERRM); 
END; 

256 ORA-00939: too many arguments for function 

所以,答案是256

編輯: 作爲建議由Bob Duell:

SELECT func_id, name, minargs, maxargs 
FROM V$SQLFN_METADATA 
WHERE name = 'COALESCE' 

FUNC_ID NAME  MINARGS MAXARGS 
387  COALESCE 2  0 

:(

編輯:

11.2.0.3上的限制似乎是65,535。

上述腳本不適用於那麼多參數。您可以通過創建並運行非常大的SQL語句來測試限制,並使用下面的腳本。

--Create a COALESCE with 65,536 functions. 
--It will fail with: ORA-00939: too many arguments for function 
--But if you remove the last argument it will work, at least on 11.2.0.3. 
--WARNING: Sending this much data through DBMS_OUTPUT may freeze some tools. 
begin 
    dbms_output.put_line('select coalesce('); 
    for i in 1 .. 6553 loop 
     dbms_output.put_line('1,2,3,4,5,6,7,8,9,0,'); 
    end loop; 
    dbms_output.put_line('1,2,3,4,5,6'); 
    dbms_output.put_line(') from dual;'); 
end; 
/
+0

+1創造力;另請參閱http://docs.oracle.com/cd/B28359_01/server.111/b28320/dynviews_3063.htm#REFRN30501 – BellevueBob

+0

@BobDuell謝謝,請閱讀我的編輯:( – Roger

+0

嵌套函數調用也不是問題,我'd認爲,所以如果超過256是必需的,這將是可能的 –