Backup in oracle db using triggers

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Backup in oracle db using triggers



I have 2 identical tables, just change the name table1 and table2, when 3 records are entered in table1 the information of this table must be copied to table 2 and table 1 must be empty again.


CREATE TABLE TABLA1(
ID_1 NUMBER PRIMARY KEY, NOMBRE VARCHAR2(40));

CREATE TABLE TABLA2(
ID_1 NUMBER PRIMARY KEY, NOMBRE VARCHAR2(40));

SELECT * FROM TABLA1;
SELECT * FROM TABLA2;


SET SERVEROUTPUT ON;
CREATE OR REPLACE TRIGGER DISP_BACKUP
BEFORE INSERT ON TABLA1
FOR EACH ROW
DECLARE
CURSOR CUR_CUENTA IS SELECT * FROM TABLA1;
--CURSOR CUR_CUENTA IS SELECT COUNT(*) FROM TABLA1;
var_rows := SQL%ROWCOUNT;
--CURCHOISE SQL%ROWCOUNT;
BEGIN
dbms_output.put_line('NUMERO DE REGISTROS EN TABLA 1' || CUR_CUENTA%ROWCOUNT
);
--OPEN CUR_CUENTA;
IF CUR_CUENTA%ROWCOUNT > 3 THEN
IF INSERTING THEN
INSERT INTO TABLA2 (ID_1,NOMBRE) VALUES (:NEW.ID_1,:NEW.NOMBRE);
END IF;
DELETE FROM TABLA1;
END IF;
END;
/





It seems you forgot to ask your question.
– PM 77-1
3 mins ago





the code does not work, the logic inside the trigger does not work. I try to use %rowcount to count the 3 records but I can not make it work.
– Carlos RdeV
29 secs ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

How to scale/resize CVPixelBufferRef in objective C, iOS