Using where clause in PL/SQL with reserved word as column name

Viewed 26

I have a column that is called CODE and that is a reserved word is PL/SQL so I am trying to select all using a where clause but it won't work. I used [ ] but it did not work. Is it different for PL/SQL?

select * 
from tab_i 
where [code] = 'jack'
1 Answers

First of all, CODE is not a reserved word in PL/SQL. So

select *
into my_record_variable 
from tab_i 
where code = 'jack';

or

select *
bulk collect into my_table_variable 
from tab_i 
where code = 'jack';

should work just fine.

Then, as to "Is it different for PL/SQL?": No. The same rules that apply for SQL delimiters apply for PL/SQL, too. Brackets, however, are not valid delimiters, neither in SQL nor in PL/SQL. The standard SQL delimiters for names are double quotes. (There exist DBMS, though, that are not standard compliant in this regard. SQL Server for instance uses brackets instead.)

Related