Pregunta

I need a list of all existing sequences and its value. I have tried:

SELECT RDB$GENERATOR_NAME, GEN_ID(RDB$GENERATOR_NAME, 0) FROM RDB$GENERATORS;

or

SELECT G.RDB$GENERATOR_NAME, GEN_ID(G.RDB$GENERATOR_NAME, 0) FROM RDB$GENERATORS G;

but these are not correct because GEN_ID() treats the first argument as a very generator name, i.e. tries to access to the generator G.RDB$GENERATOR_NAME instead of the value of G.RDB$GENERATOR_NAME

¿Fue útil?

Solución

execute block
returns (
    out_name char(31),
    out_value bigint)
as
begin
    for select rdb$generator_name from rdb$generators where rdb$system_flag is distinct from 1 into out_name do
    begin
        execute statement 'select gen_id(' || out_name || ', 0) from rdb$database' into out_value;
        suspend;
    end
end
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top