2014-09-19 50 views
0

我有一個問題關於存儲的過程,所以我有這個程序保存:Oracle存儲過程在PHP處理

CREATE OR REPLACE PROCEDURE WELTESADMIN.TOTALFABRICATION 
    (SUBCONT IN VARCHAR, PROJECT IN VARCHAR, TOTALFABRICATIONRESULT OUT NUMBER) AS 
BEGIN 
    SELECT FABRICATION.MARKING + FABRICATION.CUTTING + FABRICATION.ASSEMBLY + FABRICATION.WELDING + 
      FABRICATION.DRILLING + FABRICATION.FINISHING 
    INTO TOTALFABRICATIONRESULT 
    FROM FABRICATION 
    WHERE SUBCONT_ID = SUBCONT 
     AND PROJECT_NAME = PROJECT; 
END; 

和IM的處理,在PHP等,

$subcontValue = "RIYANTO"; 
    $projectValue = "PROCESSHOUSE"; 

    $sql = "BEGIN TOTALFABRICATION(:SUBCONT, :PROJECT); END;"; 
    $stmt = oci_parse($conn, $sql); 

    oci_bind_by_name($stmt, ":SUBCONT", $subcontValue); 
    oci_bind_by_name($stmt, ":PROJECT", $projectValue); 
    oci_define_by_name($stmt, "TOTALFABRICATIONRESULT", $result); 

    oci_execute($stmt); 

    echo $result; 

我相信,提供的所有變量都是正確的,連接是好的,並且可以在SQL PLUS 中處理,而不是在im端獲得這個錯誤,

警告:oci_execute():ORA-06550:第1行,第7列:PLS-00306:在調用'TOTALFABRICATION'時出錯的數量或類型參數ORA-06550:第1行,第7列:PL/SQL:語句忽略在C:\ XAMPP \ htdocs中\ WeltesInformationCenter \ newEmptyPHP.php上線39

回答

1

你的過程實際上有參數(二IN和一個OUT):

CREATE OR REPLACE PROCEDURE WELTESADMIN.TOTALFABRICATION 
    (SUBCONT IN VARCHAR, 
    PROJECT IN VARCHAR, 
    TOTALFABRICATIONRESULT OUT NUMBER) AS 

所以,從PHP,你應該寫:

$sql = "BEGIN TOTALFABRICATION(:SUBCONT, :PROJECT, :TOTALFABRICATIONRESULT); END;"; 
    #             ^^^^^^^^^^^^^^^^^^^^^^^ 

而且bind輸出參數一些變量:

oci_bind_by_name($stmt, "TOTALFABRICATIONRESULT", $result, 300); 
#               ^^^ 
#              maxlength 

請注意,根據the documentation

您必須指定maxlength使用OUT綁定時,使PHP分配足夠的內存來保存返回的值。

+0

感謝sylvain的建議 – marmar 2014-09-23 03:10:21