Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Please Give me a Demo Example of Creating Log file(.text/.log) Stored Procedure in PL/SQL..
Posted
Updated 28-Mar-20 4:07am
v2
Comments
[no name] 28-Sep-14 8:41am    
Nice ASAP, Urgent Require. Remove this, otherwhise the Chance is high that your question will be ignored ;)
[no name] 28-Sep-14 8:41am    
ASAP, it's not urgent at all, if it's for Oracle why did you tag your posting as SQL Server? Did you bother searching yourself for an example?

1 solution

To create a log file, use the triggers so that whenever the trigger is fired the log entry is added to the table

- Create a procedure to add record in database table
- Create Trigger on INSERT/UPDATE/DELETE and within the stored procedure insert record in log table.
 
Share this answer
 
Comments
MukeshSagar 18-Oct-14 8:05am    
Create log table:

DROP TABLE Emp_log;
CREATE TABLE Emp_log (
Emp_id NUMBER,
Log_date DATE,
New_salary NUMBER,
Action VARCHAR2(20));

Create trigger that inserts row in log table after EMPLOYEES.SALARY is updated:

CREATE OR REPLACE TRIGGER log_salary_increase
AFTER UPDATE OF salary ON employees
FOR EACH ROW
BEGIN
INSERT INTO Emp_log (Emp_id, Log_date, New_salary, Action)
VALUES (:NEW.employee_id, SYSDATE, :NEW.salary, 'New Salary');
END;
/
Update EMPLOYEES.SALARY:

UPDATE employees
SET salary = salary + 1000.0
WHERE Department_id = 20;

Result:

2 rows updated.

Show log table:

SELECT * FROM Emp_log;

Result:

EMP_ID LOG_DATE NEW_SALARY ACTION
---------- --------- ---------- --------------------
201 28-APR-10 15049.13 New Salary
202 28-APR-10 6945.75 New Salary

2 rows selected.
CHill60 18-Oct-14 8:09am    
Did you know you can use the "Improve Answer" link to add this code into your solution. It has the advantage that you can format it properly

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900