想写一个传递参数建立用户的存储过程,一直没有写出来,到自己加的群里问了问,说要用到动态SQL,就上网查找关于动态SQL的信息。资料是查了很多,就是不知道怎么写。后来好不容易编译通过了,发现测试的时候报错误。最后再根据网上的资料改写,最终成功了。不过这个存储过程要在sys用户下运行,才能正常运行。在system下说是权限不够。
下边是编译运行成功的例子,放在这里以供参考:
create or replace procedure createUser(Uname char,passwd char)
as
createSQL char(50);
grantSQL char(50);
begin
createSQL:='create user '||Uname||' identified by '||passwd||'';
grantSQL:='grant dba to '||Uname||'';
execute immediate createSQL;
dbms_output.put_line(createSQL);
execute immediate grantSQL;
end;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22275400/viewspace-752725/
,如需转载,请注明出处,否则将追究法律责任。