String problem in oracle

0

I am making a condition to add a field in the database, that is, it will only add if the condition is equal to 0. The problem is that in my execute immediate statement it says that the word PRIMARY is invalid. This is because it should be in single quotation marks ('') but how can I handle this since the entire query is already quoted? Detail: If it is a number it works since it does not need quotation marks.

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;
    
asked by anonymous 01.09.2017 / 16:20

1 answer

0
  

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

Try two quotation marks, for example:

(I'm not with Oracle on my machine, but it works the same on Oracle!)

    
01.09.2017 / 16:29