gostaria de saber como passo no nome da tabela como parametro
create or alter procedure TESTE (
TABLENAME varchar(30),
STATUS varchar(1))
returns (
INCREMENT integer)
as
declare variable RESULT varchar(254);
begin
if (STATUS = 'T') then
begin
for select rdb$generator_name from rdb$generators
where rdb$system_flag is distinct from 1 and rdb$generator_name = 'GEN_' || upper(:TABLENAME) || '_ID' into RESULT do
execute statement 'select gen_id(' || upper(trim(RESULT)) || ', 0) from rdb$database' into increment;
/* funciona */
while (exists(SELECT * FROM EMPRESAS WHERE EMPRESAS_ID = :incremento)) do
incremento = incremento + 1;
/* nao funciona */
/*
while (exists(execute statement 'select * from ' || trim(:TABLENAME) || ' where ' || trim(:TABLENAME) || '_ID = ' || :increment)) do
increment = increment + 1;
*/
suspend;
end
end