在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;
/
这些方法可以帮助您记录执行语句并创建一个简单的日志功能。您可以根据需要进行调整和扩展。