DECLARE
text VARCHAR2(20) := &text;
BEGIN
DBMS_OUTPUT.PUT_LINE(text);
END;
When I declare this anonymous block so that the user enters a value by keyboard, it shows me an error in the console output.
This is the error:
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:
CodePudding user response:
As this is a substitution variable whose datatype is varchar2
, enclose it into single quotes (as any other string):
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>
CodePudding user response:
In this block, you are trying to pass another variable Hello (not its value) to the text variable. Use apostrophes to make the compiler interpret it as a value and not as a variable - 'Hello'
DECLARE
text VARCHAR2(20) := Hello; --<< change to 'Hello'
START
DBMS_OUTPUT.PUT_LINE(text);
END;