DECLARE
text VARCHAR2(20) := &text;
BEGIN
DBMS_OUTPUT.PUT_LINE(text);
END;
當我宣告這個匿名塊以便用戶通過鍵盤輸入一個值時,它會在控制臺輸出中顯示一個錯誤。
這是錯誤:
Error starting at line: 3 of the command:
DECLARE
text VARCHAR2(20) := Hello;
START
DBMS_OUTPUT.PUT_LINE(text);
END;
Bug report -
ORA-06550: line 2, column 26:
PLS-00201: identifier 'HELLO' must be declared
ORA-06550: line 2, column 10:
PL/SQL: Item ignored
ORA-06550: line 4, column 25:
PLS-00320: The type declaration of this expression is incomplete or has a wrong format.
incorrect
ORA-06550: line 4, column 4:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
uj5u.com熱心網友回復:
由于這是一個資料型別為 的替換變數varchar2,請將其括在單引號中(與任何其他字串一樣):
SQL> declare
2 text varchar2(20) := '&text'; --> this
3 begin
4 dbms_output.put_line(text);
5 end;
6 /
Enter value for text: Hello
old 2: text varchar2(20) := '&text';
new 2: text varchar2(20) := 'Hello';
Hello
PL/SQL procedure successfully completed.
SQL>
uj5u.com熱心網友回復:
在此塊中,您嘗試將另一個變數Hello(不是它的值)傳遞給text變數。使用撇號使編譯器將其解釋為值而不是變數 - 'Hello'
DECLARE
text VARCHAR2(20) := Hello; --<< change to 'Hello'
START
DBMS_OUTPUT.PUT_LINE(text);
END;
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/472558.html
