String problem in oracle

Asked

Viewed 207 times

0

I am making a condition to add a field in the database, IE, will only add if the condition is equal to 0. The problem is that in my instruction execute immediate He says the word PRIMARIO is invalid. This is because it should be with simple quotes('') but how can I treat this since all the query is already with quotes ? Detail: If it is a number works since it does not need quotes.

declare 
 col_count  integer;
begin 
 select count(*)
   into col_count
 from user_tab_columns
 where table_name = 'BALANCA'
 and column_name = 'TIPO';
 if col_count = 0 then
    execute immediate 'ALTER TABLE BALANCA ADD TIPO varchar2(255 char) default PRIMARIO not null';
    commit;
 end if;
end;

1 answer

0

execute 'ALTER TABLE BALANCE ADD TYPE varchar2(255 char) default PRIMARIO not null';

Try two quotes, for example:

inserir a descrição da imagem aqui

(I don’t have Oracle on my machine, but it works the same on Oracle!)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.