1

以下程序:

create or replace
PROCEDURE ChangePassword
(
    p_Name      VARCHAR2,
    p_Password  VARCHAR2
)
AS
  EXECUTE IMMEDIATE 'ALTER USER :a IDENTIFIED BY :b' USING p_Name, p_Password;
END;

编译成功,但执行时:

exec ChangePassword('TestUser', 'newPassword');

导致错误:

01935. 00000 -  "missing user or role name"
*Cause:    A user or role name was expected.
*Action:   Specify a user or role name.

为什么?

4

2 回答 2

5

您不能使用绑定变量代替标识符,例如此语句中的用户名。解析语句时需要知道标识符的值,而绑定值在解析之后、执行之前合并。

于 2012-04-25T12:10:18.647 回答
4

我认为以下内容会起作用

create or replace PROCEDURE ChangePassword(p_Name         IN VARCHAR2,
                                           p_Old_password IN VARCHAR2,
                                           p_New_password IN VARCHAR2)
AS
  EXECUTE IMMEDIATE 'ALTER USER ' || p_name ||
                    ' IDENTIFIED BY ' || p_New_password ||
                    ' REPLACE ' || p_Old_password;
END;

分享和享受。

于 2012-04-25T12:13:26.743 回答