R
R
Raushka2021-06-01 15:57:51
Oracle
Raushka, 2021-06-01 15:57:51

When working with dynamic SQL error invalid identifier, how can I fix it?

All hello guys!
Can you help in solving the problem (I need to update certain data in the 'tablename' table, the data that is taken from general_table )

declare
  tablename varchar(255) := 'CoolTable';
BEGIN
  select functable (tablename) into tablename from dual;  --возвращает наличие таблицы 
  for rec in (select g.acode, g.clcode  from general_table g  where rownum = 1) loop
 if tablename is not null then
execute immediate 'update ' || tablename || ' set accli = ' || rec.acode || ', clcode= ' || rec.clcode || ''; --данные из таблы general_table обновляются в таблице tablename
end if;
end loop;
end;

ORA-00904: "8989123123": недопустимый идентификатор 
ORA-06512: на  line 16


Both in the 'tablename' table and in the general_table table, all fields of type Varchar2(100), what else could be the error?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2021-06-01
@Raushka

The varchar literals must be quoted:

execute immediate 'update ' || tablename || ' set accli = ''' || rec.acode || ''', clcode= ''' || rec.clcode || '''';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question