【问题标题】:oci_execute(): ORA-06550: PLS-00306: wrong number or types of argumentsoci_execute(): ORA-06550: PLS-00306: 错误的参数数量或类型
【发布时间】:2018-12-17 12:47:25
【问题描述】:

我已经使用下面的代码来执行一个使用 php 的 oracle 存储过程。

$s = oci_parse($db, 'begin :bind2 := XXXXXXXXX(:bind1); end;');

if(!$s)
{
    echo "wrong"; 
}
else
{
    echo "Right";
    $in_var = 'XXXXXXX';
    $in = oci_bind_by_name($s, ':bind1', $in_var);

    if(!$in)
    {
        echo "Incorrect in";
    }
    else
    {
        echo "Correct in";
        $cursor = oci_new_cursor($db);
        // On your code add the latest parameter to bind the cursor resource to the Oracle argument
        $k = oci_bind_by_name($s,':bind2', $cursor, -1, OCI_B_CURSOR);
        if(!$k)
        {
            echo "Wrong";
        }
        else
        {
            echo "Correct";
            // Execute the statement as in your first try
            $execute = oci_execute($s) or die ("Unable to execute query\n");
            if(!$execute)
            {
                echo "false";
            }
            else
            {
                echo "correct";
                // and now, execute the cursor
                $result = oci_execute($cursor,OCI_DEFAULT);
                echo $result;
                //oci_bind_by_name($s, ":bind2", $out_var, 20); // 20 is the return length
                //oci_execute($s,OCI_DEFAULT);
                //echo "Procedure returned value: " . $out_var;

                // Logoff from Oracle...
                oci_free_statement($s);
                oci_close($db);
            }
        }
    }
}

执行上述代码 sn-p 后出现以下错误。

"oci_execute(): ORA-06550: 第 1 行第 7 列: PLS-00306: 错误编号 或调用“XXXXXXXXX”的参数类型 ORA-06550:第 1 行,第 1 列 7:PL/SQL:语句被忽略 /opt/lampp/htdocs/usermanagemet/callOraProc.php 在第 79 行无法 执行查询”

我的程序是:

CREATE OR REPLACE FUNCTION XXXXXXXXX(
    username IN VARCHAR2)
  RETURN VARCHAR2
AS
  v_query VARCHAR2( 100);
  v_out   VARCHAR2(20);
BEGIN
  v_query := 'ALTER USER '|| username ||
    ' ACCOUNT LOCK
    PROFILE GNVLOCK';

  --dbms_output.put_line(v_query);
  EXECUTE immediate v_query;
  RETURN 'true';
EXCEPTION
WHEN OTHERS THEN
  RETURN SQLCODE;
END SLT_GNVUSER_DISABLE;

有人知道我在这里缺少什么吗?

【问题讨论】:

    标签: php oracle


    【解决方案1】:

    您的代码的问题似乎是您将 Oracle 对象视为一个过程,而它实际上是一个函数。

    您使用过:

    $s = oci_parse($db, 'begin XXXXXXXXX(:bind1, :bind2); end;');
    

    你应该改用:

    $s = oci_parse($db, 'begin :bind2 := XXXXXXXXX(:bind1); end;');
    

    这将执行XXXXXXXXX,结果将如您所期望的那样以:bind2结束。

    您使用的第一个语法适用于具有OUT 参数的过程,您可以通过bind2 访问该参数。

    顺便说一下,我不知道您是选择了函数命名方案还是继承了它,但XXXXXXXXX 似乎对您的函数来说是一个非常不具描述性的名称。

    【讨论】:

    • 感谢您的及时回复。我更正了您提到的步骤。现在我收到以下错误。 “警告:oci_execute():ORA-06550:第 1 行,第 17 列:PLS-00382:表达式类型错误 ORA-06550:第 1 行,第 7 列:PL/SQL:/opt/lampp/htdocs/ 中忽略的语句第 80 行的 usermanagemet/callOraProc.php 无法执行查询”
    • 是否需要转换:bind2的数据类型。 ?因为它返回的是布尔值“true”。
    • 您的代码仍然显示原始问题,因此很难判断您现在在做什么。 (您可以编辑您的原始帖子)。 PL/SQL 函数现在返回一个字符串。确保您没有将其绑定为 OCI_B_CURSOR。如果您需要更多示例,请查看 Oracle 免费书籍 oracle.com/technetwork/topics/php/… 的“使用 PL/SQL WITH OCI8”一章
    • 感谢您的回复。我已经更新了我的代码。我会检查你提到的:)
    猜你喜欢
    • 1970-01-01
    • 2012-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-09
    • 1970-01-01
    • 2015-09-09
    • 1970-01-01
    相关资源
    最近更新 更多