2017-08-04 35 views
-1

我執行一個PL/SQL程序,但我得到的錯誤PLS-00201:必須聲明錯誤PLS-00201:標識符kurtwb必須聲明

DECLARE 
create_user dba_users%ROWTYPE; 
model_id varchar2(20); 
user_name varchar2(20); 
BEGIN 
model_id:=&model_id; 
user_name:=&user_name; 
Select * INTO create_user from dba_users where username=model_id; 
EXECUTE IMMEDIATE 'create user user_name identified by password 
user_name default tablespace create_user.default_tablespace 
temporary tablespace create_user.temporary_tablespace profile 
create_user.profile;'; 
END; 
/

標識符下面「KURTWB」是輸入的值由我

Enter value for model_id: kurtwb 
old 6: model_id:=&model_id; 
new 6: model_id:=kurtwb; 
Enter value for user_name: rohit 
old 7: user_name:=&user_name; 
new 7: user_name:=rohit; 

下面是我得到

ERROR at line 6: 
ORA-06550: line 6, column 11: 
PLS-00201: identifier 'KURTWB' must be declared 
ORA-06550: line 6, column 1: 
PL/SQL: Statement ignored 
ORA-06550: line 7, column 12: 
PLS-00201: identifier 'ROHIT' must be declared 
ORA-06550: line 7, column 1: 
PL/SQL: Statement ignored  
+0

什麼是你的問題? – yanman1234

回答

0

您已經進入kurtwb錯誤作爲名爲&model_id的替代變量的值。
SQLPLUS(或Oracle-SQL-Developer`)替代在此行這個變量:

BEGIN 
    model_id:=&model_id; 
    .... 
    .... 

與輸入值kurtwb。取代後的代碼如下所示:

BEGIN 
    model_id:=kurtwb; 
    .... 
    .... 

因爲kurtwb沒有定義任何地方,你會得到PLS-00201: identifier 'KURTWB' must be declared錯誤。


我猜你想存儲kurtwb作爲一個字符串變量model_id,在這種情況下,你必須使用apostropher的和身邊替換變量:

BEGIN 
    model_id:='&model_id'; 
    .... 
    .... 
+0

我猜錯誤是'identifier'ROHIT'必須聲明':)呃,這個anwer是完全一樣的,除了你必須用'user_name:=&user_name;'替換'model_id:=&model_id;'在答案中。 – krokodilko

+0

嗨krokodilko 感謝您的回覆。通過您提供的方法解決上述問題。但現在在行中出現新錯誤 EXECUTE IMMEDIATE'create user'|| user_name ||由'|| user_name ||'標識的' 默認表空間' || create_user.default_tablespace ||'臨時表空間' || create_user.temporary_tablespace ||' profile' || create_user.profile ||';'; END; / DECLARE * ERROR位於第1行: ORA-00911:無效字符 ORA-06512:在第12行 – Rohit

+0

喜Krokodilko我所做的更改 MODEL_ID:= '&MODEL_ID'; user_name:='&user_name'; 然後我也收到錯誤 – Rohit