I'm trying to capture the last id
registered in a table (USE ORACLE 11G) and searching the internet I found this post .
I did not find much information in Spanish that's why I'm only using this post as a reference, but it does not work for me. In the post it indicates that we have to create a trigger and then capture the id
entered, through a returning into
but at the moment of executing the statement of insert
along with the returning
I get an error, but if I execute only the insert
no problem. In theory, the two instructions should be executed together.
In particular I get the sgt error:
"ORA-01008: NOT ALL VARIABLES BOUND".
/*CREANDO SECUENCIAS*/
create sequence id_pedido
start with 1
increment by 1;
/*CREO LA TABLA PADRE*/
create table pedidos_padre(
id_pedidos_padre int primary key,
id_usuario int,
fecha_registro date,
nom_cliente varchar(150),
foreign key(id_usuario)
references usuario(id_usuario)
);
/*creo un disparador para capturar el ultimo id generado*/
CREATE OR REPLACE TRIGGER pedidos_padre_bit
BEFORE INSERT ON pedidos_padre
FOR EACH ROW
BEGIN
SELECT id_pedido.NEXTVAL
INTO :new.id_pedidos_padre
FROM dual;
END;
insert into pedidos_padre(id_pedidos_padre,id_usuario,fecha_registro,nom_cliente)
values(id_pedido.nextval,2,sysdate,'rayito')
RETURNING id_pedidos_padre INTO :last_insert_id
Thanks in advance.