w3resource

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:

Flowchart: PL/SQL DataType - Block to learn how to declare a character type variable
Flowchart: PL/SQL DataType - Block to learn how to declare a character type variable
Flowchart: PL/SQL DataType - Block to learn how to declare a character type variable

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:

Flowchart: PL/SQL DataType - Block to learn how to declare a character type variable

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?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/plsql-exercises/datatype/plsql-datatype-exercise-1.php