Oracle Error PLS-00363: expression ‘string’ cannot be used as an assignment target

Oracle Error Message

PLS-00363: expression ‘string’ cannot be used as an assignment target

Reason for the Error

Oracle Error PLS-00363: expression’string’ cannot be used as an assignment target is a common error that can occur when working with PL/SQL code in Oracle. This error usually occurs when you try to use an expression as the target of an assignment statement and the expression cannot be assigned a value.

For example,

DECLARE
   num1 NUMBER := 10;
   num2 NUMBER := 20;
   str VARCHAR2(20) := 'Hello';
BEGIN
   str := num1 + num2;
END;

The PL/SQL block in this example attempts to assign the value of num1 + num2 to the variable str. However, num1 + num2 is a numeric expression that cannot be assigned to a VARCHAR2 variable.

Solution

Correct the statement by using a valid assignment target.

You must confirm that the expression used as the assignment statement’s target may accept a value if you want to correct this mistake. You might correct the issue in the example above by changing the str variable’s data type to a numeric type:

DECLARE
   num1 NUMBER := 10;
   num2 NUMBER := 20;
   str NUMBER;
BEGIN
   str := num1 + num2;
END;

You could also change the expression in the assignment statement to return a value of the correct data type:

DECLARE
   num1 NUMBER := 10;
   num2 NUMBER := 20;
   str VARCHAR2(20) := 'Hello';
BEGIN
   str := TO_CHAR(num1 + num2);
END;

In this example, the TO CHAR function is used to convert the numeric expression num1 + num2 to a string value that can be assigned to the str variable.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Oracle Error Message CLSGN-32767: Internal error. Reason for the Error An unexpected error occurred. Solution Examine the message(s) that accompany...
Oracle Error Message CLSGN-00211: OCR batch operation failed. string Reason for the Error Setting a set of Oracle Cluster Registry...
Oracle Error Message CLSGN-00210: failed to get value for OCR key “string”. string Reason for the Error It was not...