在Oracle數據庫中,您可以使用以下方法將執行語句寫入日志:
SET SERVEROUTPUT ON;
DECLARE
v_sql VARCHAR2(1000);
BEGIN
v_sql := 'SELECT * FROM employees';
dbms_output.put_line('Executing SQL statement: ' || v_sql);
EXECUTE IMMEDIATE v_sql;
END;
/
CREATE TABLE log_table (
log_id NUMBER,
log_time TIMESTAMP,
sql_statement VARCHAR2(1000)
);
DECLARE
v_sql VARCHAR2(1000);
BEGIN
v_sql := 'SELECT * FROM employees';
INSERT INTO log_table (log_id, log_time, sql_statement)
VALUES (1, SYSTIMESTAMP, 'Executing SQL statement: ' || v_sql);
EXECUTE IMMEDIATE v_sql;
INSERT INTO log_table (log_id, log_time, sql_statement)
VALUES (2, SYSTIMESTAMP, 'SQL statement executed successfully');
END;
/
這些方法可以幫助您記錄執行語句并創建一個簡單的日志功能。您可以根據需要進行調整和擴展。