Advertisement
rex9840

Untitled

Aug 4th, 2024
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. DROP TABLE employee;
  2. DROP TABLE student5;
  3. DROP TABLE AUDIT_TRAIL;
  4.  
  5.  
  6.  
  7. CREATE TABLE employee(
  8. empid NUMBER(5),
  9. empname VARCHAR2(50),
  10. address VARCHAR2(100),
  11. contactno NUMBER(10)
  12. );
  13.  
  14. CREATE TABLE audit_trail(
  15. empid_val NUMBER(5),
  16. empname_val VARCHAR2(50),
  17. op_date DATE,
  18. operation VARCHAR2(100));
  19.  
  20.  
  21. INSERT INTO employee VALUES(1, 'Rupesh Nepal','KTM','98404050');
  22.  
  23.  
  24. CREATE OR REPLACE TRIGGER trig_audittrail
  25. after INSERT ON employee
  26. FOR each ROW
  27. BEGIN
  28. INSERT INTO audit_trail(
  29.  empid_val,
  30.  empname_val,
  31.  op_date,
  32.  operation)
  33.  VALUES
  34.  (
  35.  :NEW.empid,
  36.  :NEW.empname,
  37.  SYSDATE,
  38.  'Record Insertion'
  39.  );
  40.  END trig_audittrail;
  41.  
  42. SELECT * FROM AUDIT_TRAIL ;
  43.  
  44. INSERT INTO employee VALUES(2, 'RAMU KAKA ','LALT','978343434');
  45. COMMIT;
  46.  
  47. SELECT * FROM employee;
  48.  
  49. DELETE FROM employee;
  50. COMMIT;
  51.  
  52. INSERT INTO employee VALUES(15,'Nepal','PKH','980000405');
  53. COMMIT;
  54.  
  55. SELECT empname, versions_starttime "START_DATE", versions_endtime
  56. "END_DATE"
  57. FROM EMPLOYEE versions BETWEEN scn minvalue AND maxvalue WHERE empid=1;
  58.  
  59.  
  60.  
  61. CREATE TABLE student5(
  62. rollno NUMBER(4),
  63. name VARCHAR2(50),
  64. address VARCHAR2(50),
  65. contactno NUMBER(10)
  66. );
  67.  
  68. INSERT INTO student5 VALUES(1,'student','KTM',1234);
  69. COMMIT;
  70.  
  71. SELECT * FROM student5;
  72.  
  73.  
  74. UPDATE student5 SET name='Rupesh' WHERE rollno=1;
  75. SELECT * FROM student5 ;
  76.  
  77.  
  78. SELECT * FROM student5;
  79. ROLLBACK;
  80. SELECT * FROM student5;
  81. COMMIT;
  82.  
  83. SELECT name, versions_starttime "START_DATE", versions_endtime
  84. "END_DATE"
  85. FROM STUDENT5 versions BETWEEN scn minvalue AND maxvalue WHERE rollno=1
  86.  
  87.  
  88. -- Create the table
  89. CREATE TABLE Employee (
  90.     EMPNAME VARCHAR2(100),
  91.     START_DATE TIMESTAMP,
  92.     END_DATE TIMESTAMP
  93. );
  94.  
  95. -- Insert values into the table
  96. -- Insert values into the table
  97. INSERT INTO Employee (EMPNAME, START_DATE, END_DATE) VALUES
  98. ('Rupesh Nepal', TO_TIMESTAMP('2024-06-17 17:32:40.000', 'YYYY-MM-DD HH24:MI:SS.FF3'), NULL);
  99.  
  100. INSERT INTO Employee (EMPNAME, START_DATE, END_DATE) VALUES
  101. ('Rupesh Nepal', TO_TIMESTAMP('2024-06-17 17:37:10.000', 'YYYY-MM-DD HH24:MI:SS.FF3'), TO_TIMESTAMP('2024-06-17 17:37:10.000', 'YYYY-MM-DD HH24:MI:SS.FF3'));
  102.  
  103. -- Commit the transaction
  104. COMMIT;
  105. SELECT * FROM  EMPLOYEE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement