PL/SQL DataType: Block to learn how to declare a character type variable
PL/SQL DataType: Exercise-1 with Solution
Write a PL/SQL block to learn how to declare a character type variable.
Sample Solution:
PL/SQL Code:
DECLARE
c VARCHAR2(8 CHAR);
BEGIN
c := 'abc ';
END;
/
or can also be declare like this-
DECLARE
c VARCHAR2(8);
BEGIN
c := 'abc ';
END;
/
if you declare like this and used to insert too long data, see an error message will appear.
DECLARE
c VARCHAR2(3);
BEGIN
c := 'abc ';
END;
/
Sample Output:
DECLARE * ERROR at line 1: ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at line 4
Flowchart:
or also the error message will appear if you declare like this at the time of inserting too long data -
DECLARE
c VARCHAR2(3 CHAR);
BEGIN
c := 'abc ';
END;
/
Sample Output:
DECLARE * ERROR at line 1: ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at line 4
Flowchart:
Improve this sample solution and post your code through Disqus
Previous: PL/SQL DataType Exercises Home.
Next: Write a PL/SQL block to insert data to a table using character type variable.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics