ORA-06550:第15行第7列:\ nPLS-00103:遇到符号“BEGIN”

时间:2016-12-04 21:49:27

标签: php oracle stored-functions

我正在尝试使用PHP引擎v5.1和PHP OCI扩展模块从php脚本在包中执行存储的oracle函数。为此目的,我有2个plsql块,它将获取pk member_id和product_id,并将用于执行该函数。在此过程中,我收到以下错误

  

ORA-06550:第15行第7列:\ nPLS-00103:遇到符号   “BEGIN”

我不确定如何解决此错误?

<?php
$conn = oci_connect("username","password","localdb");

$CONFIG_NAME='DirectType';
$BUS_SEG_CODE='';
$PRODUCT_NUM='130342';
$MEMBER_NAME='87307-3';
$EFFECTIVE_DATE=strtotime('2016-12-01');
$MODEL_DATE=time();
$CURRENCY='USD';
$REALM_NUM=1024;
$RESOLVED_PRICE=111;
$RESOLVED_CURRENCY='USD';

if ($conn) {
    echo "Connection Successful"."\n";
    echo "System time is ".time();

   $sql_proc = "
   DECLARE
    v_MEMBER_ID NUMBER;
    v_PRODUCT_ID NUMBER;

  BEGIN
   SELECT cat_map_id INTO v_PRODUCT_ID
    FROM mn_cat_map WHERE product_num = :PRODUCT_NUM and catalog_type = 'INT';
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    dbms_output.put_line('Product Error');
    return;
  END;

  BEGIN
   SELECT member_id INTO v_MEMBER_ID
    FROM mn_member WHERE member_name = :MEMBER_NAME;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    dbms_output.put_line('Customer Error');
    return;
  END;

   BEGIN PACKAGE_NAME.function_name(
   :CONFIG_NAME,
   :BUS_SEG_CODE,
   v_MEMBER_ID,
   v_PRODUCT_ID,
   :EFFECTIVE_DATE,
   :MODEL_DATE,
   :CURRENCY_CODE,
   :REALM_NUM,
   :RESOLVED_PRICE,
   :RESOLVED_CURRENCY
   );
   END;
   ";

   $stmt = oci_parse($conn,$sql_proc);
   //  Bind the input parameter

   oci_bind_by_name($stmt,':CONFIG_NAME',$CONFIG_NAME);
   oci_bind_by_name($stmt,':BUS_SEG_CODE',$BUS_SEG_CODE);
   oci_bind_by_name($stmt,':EFFECTIVE_DATE',$EFFECTIVE_DATE);
   oci_bind_by_name($stmt,':MODEL_DATE',$MODEL_DATE);
   oci_bind_by_name($stmt,':CURRENCY_CODE',$CURRENCY);
   oci_bind_by_name($stmt,':REALM_NUM',$REALM_NUM);
   oci_bind_by_name($stmt,':RESOLVED_PRICE',$RESOLVED_PRICE);
   oci_bind_by_name($stmt,':RESOLVED_CURRENCY',$RESOLVED_CURRENCY);

  // Parse the statement. Note there is no final semi-colon in the SQL statement
    $result=oci_execute($stmt);

    if (!$result){
        $e = oci_error($stmt);  // For oci_execute errors pass the statement handle
        print htmlentities($e['message']);
        print "\n<pre>\n";
        print htmlentities($e['sqltext']);
        printf("\n%".($e['offset']+1)."s", "^");
        print  "\n</pre>\n";

    }
    else {
        echo "Execute STMT returns True or False : ".$result;
        echo "Resolved Price is : ".$RESOLVED_PRICE. "\n";
    }
    echo "</pre>";
    oci_free_statement($stmt);
    oci_close($conn);
}
else {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
?>

1 个答案:

答案 0 :(得分:1)

将所有内容放在一个块中,而不是3个单独的块:

改变这个:

DECALRE
...
BEGIN
...
END;
BEGIN
...
END;
BEGIN
...
END;

到此:

DECLARE
...
BEGIN
SELECT ..
SELECT ..
FUNCTION CALL ..
END;