以下程序:
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.
为什么?
答案 0 :(得分:5)
您不能使用绑定变量代替标识符,例如此语句中的用户名。解析语句时需要知道标识符的值,而在执行之前解析后合并绑定值。
答案 1 :(得分: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;
分享并享受。