SQLize
Online
/
PHPize Online
/
SQLtest Online
A
A
A
Share
Donate
Blog
Popular
Donate
A
A
A
Share
Blog
Popular
SQLize.online is a free online SQL environment for quickly running, experimenting with and sharing code.
You can run your SQL code on top of the most popular RDBMS including MySQL, MariaDB, SQLite, PostgreSQL, Oracle and Microsoft SQL Server.
SQL code:
Upload
Copy
Format
Clear
CREATE TABLE facility_audit_log ( log_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, table_name VARCHAR2(100), column_name VARCHAR2(100), old_value VARCHAR2(4000), -- 根據需要調整長度 new_value VARCHAR2(4000), -- 根據需要調整長度 modified_by VARCHAR2(100), modified_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE OR REPLACE TRIGGER after_sml_am_facility_update AFTER INSERT OR UPDATE ON SML_AM_FACILITY FOR EACH ROW DECLARE v_old_value VARCHAR2(4000); v_new_value VARCHAR2(4000); -- 用於存儲動態生成的 SQL 語句 BEGIN -- 动态生成插入语句,记录所有列的值 FOR col IN (SELECT column_name FROM all_tab_cols WHERE table_name = 'SML_AM_FACILITY' AND column_name NOT IN ('CREATION_DATE', 'LAST_UPDATE_DATE')) -- 排除自动生成列 LOOP -- 動態獲取舊值和新值 EXECUTE IMMEDIATE 'SELECT :OLD.' || col.column_name || ' FROM dual' INTO v_old_value USING :OLD; EXECUTE IMMEDIATE 'SELECT :NEW.' || col.column_name || ' FROM dual' INTO v_new_value USING :NEW; -- 插入審計記錄(無論是否有更新) INSERT INTO facility_audit_log (table_name, column_name, old_value, new_value, modified_by) VALUES ('SML_AM_FACILITY', col.column_name, v_old_value, v_new_value, USER); END LOOP; END;
SQL
Server:
MariaDB 11.4
MariaDB 11.5
MariaDB 10
MariaDB 10 Sakila (ReadOnly)
MySQL 5.7
MySQL 5.7 Sakila (ReadOnly)
MySQL 8.0
MySQL 8.0 Sakila (ReadOnly)
SQLite 3
SQLite 3 Preloaded
PostgreSQL 10 Bookings (ReadOnly)
PostgreSQL 11
PostgreSQL 12
PostgreSQL 13
PostgreSQL 14
PostgreSQL 15
MS SQL Server 2017
MS SQL Server 2019
MS SQL Server 2022
MS SQL Server 2022 AdventureWorks (ReadOnly)
Firebird 4.0
Firebird 4.0 (Employee)
Oracle Database 19c (HR)
Oracle Database 21c
Oracle Database 23c Free
SOQOL
Version
ER Diagram
Preserve result
Stuck with a problem?
Got Error?
Ask ChatGPT!
Result:
Copy
Clear