Variable name and table column name same
I defined variables with same name as that of table columns in a procedure.
UPDATE student SET first_name = first_name WHERE id = 2000;
Here it is treating both first_name as column names.
can anyone explain when it treat it as variable? When it treat it as a column name?
Re: Variable name and table column name same
Hi,
Whenever the variable names are same as column names of the table, oracle treats them as columns rather than variables.
This is coz, values are assigned to variables using the assignment operator ":=" while columns using "=".
So, when the variable name and column name is same and is updated as "update table_name set first_name=first_name" it considers it as column and updates the column.
Regards,
Savitha
Re: Variable name and table column name same
It is strongly recommended not to use same name for coulmn and a variable.