Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Bases de datos > Firebird e Interbase
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 25-11-2004
anavarro anavarro is offline
Registrado
 
Registrado: nov 2004
Posts: 1
Poder: 0
anavarro Va por buen camino
Como lograr el último ID insertado?

Me gustaria saber si existe algún método o sentencia en Firebird 1.5 que devuelva el último ID insertado. En mysql si existe last_insert_id(), que devuelve el último indentificador insertado en un campo autoincrementable. Esta funcion creo que no existe en Firebird y quisiera saber si hay alguna que haga lo mismo, o en su caso como lo podria hacer.

Gracias.
Responder Con Cita
  #2  
Antiguo 25-11-2004
Avatar de LordBits
LordBits LordBits is offline
Miembro
 
Registrado: nov 2004
Posts: 15
Poder: 0
LordBits Va por buen camino
esta es la solucion que dan en www.ibphoenix.com..

Assume that you have already created a generator in your database as:

CREATE GENERATOR my_gen_id;

Examples:
Method 1: (SQL)
SELECT DISTINCT(GEN_ID(my_gen_id, 0))FROM table_name;
NOTE: Please notice that the increment value is (0) zero. This is to ensure
that you do not increment the generator when querying for its next value.

Method 2: (ISQL)
While attached to the database via an ISQL session type the following.
SQL> SHOW GENERATOR my_gen_id;

Method 3: (STORED PROCEDURE)
Code:
SET TERM !!;
CREATE PROCEDURE get_next_gen_value
RETURNS (next_value INTEGER)
AS
BEGIN
next_value = GEN_ID(my_gen_id, 0);
SUSPEND;
END !!
SET TERM ;!!

NOTE: Please notice that the increment value is (0) zero. This is to ensure
that you do not increment the generator when querying for its next value.
Once the procedure is successfully created you can issue a SELECT statement
against it.

SQL:
SELECT * FROM get_next_gen_value;
Responder Con Cita
  #3  
Antiguo 25-11-2004
Avatar de defcon1_es
defcon1_es defcon1_es is offline
Miembro
 
Registrado: mar 2004
Ubicación: Cuenca - España
Posts: 533
Poder: 21
defcon1_es Va por buen camino
Hola,
si al campo ID le asignas su valor mediante un generador,
puedes usar : GEN_ID(<MiGenerador>, 0)

Esta función devuelve el valor actual del Generador,
es decir, del último ID insertado.

Salu2.
__________________
Progress Openedge
https://abevoelker.com/progress_open...dered_harmful/


Delphi forever...
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 23:59:22.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi