问题描述
我使用 Oracle XE 的唯一目的是开发 PHP 应用程序,而 11g 版显然失去了 10g 曾经拥有的用于管理用户的 GUI 工具,因此我想准备一个代码片段来从命令行创建用户.我正在尝试 定义变量所以我不需要输入相同的用户名 16 次,但我无法获得正确的语法:
<块引用>
是否禁止在 PL/SQL 块中使用 CREATE USER
语句,或者我只是犯了一个愚蠢的错字?是否必须使用 SQL*Plus 变量?
PLS-00103:在预期以下情况之一时遇到符号CREATE":
上述错误是因为您在 PL/SQL 中使用了 DDL.你不能这样做.您必须 (ab) 使用 EXECUTE IMMEDIATE 在 PL/SQL 中发出 DDL 语句.
例如
来自文档的快速参考,
<块引用>在 PL/SQL 中执行 DDL 和 SCL 语句
只有动态SQL可以执行以下类型的语句在 PL/SQL 程序单元中:
数据定义语言 (DDL) 语句,例如
CREATE
、DROP
、GRANT
和撤销
会话控制语言 (SCL) 语句,例如
ALTER SESSION
和SET ROLE
SELECT
语句中的TABLE
子句
顺便提一下,
创建用户和授予权限通常是由 DBA 负责的数据库管理任务.这不是通过 PL/SQL 程序完成的频繁活动.DBA 创建用户并授予必要的权限作为一次性活动.
I use Oracle XE for the sole purpose of developing PHP applications and version 11g has apparently lost the GUI tool to manage users which 10g used to have so I'd like to prepare a code snippet to create users from command line. I'm trying to define variables so I don't need to type the same user name 16 times but I can't get the syntax right:
Is it forbidden to use a CREATE USER
statement from within a PL/SQL block or I simply made a silly typo? Is it mandatory to use SQL*Plus variables?
PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
The above error is because of the fact that you are using DDL inside PL/SQL. You cannot do that. You must (ab)use EXECUTE IMMEDIATE to issue DDL statements in PL/SQL.
For example,
Quick reference from documentation,
Executing DDL and SCL Statements in PL/SQL
Only dynamic SQL can execute the following types of statements within PL/SQL program units:
Data definition language (DDL) statements such as
CREATE
,DROP
,GRANT
, andREVOKE
Session control language (SCL) statements such as
ALTER SESSION
andSET ROLE
- The
TABLE
clause in theSELECT
statement
On a side note,
Creating users and granting privileges are usually database administration tasks taken care by the DBA. It is not a frequent activity done via PL/SQL program. DBA creates the users and grants the necessary privileges as a one time activity.
这篇关于从 PL/SQL 块中的字符串变量创建用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!