使用after create 建立trigger記錄procedure PL/SQL程式碼變更
How does one keep a history of PL/SQL code changes?
One can build a history of PL/SQL code changes by setting up an AFTER CREATE schema (or database) level trigger (available from Oracle 8.1.7). This will allow you to easily revert to previous code should someone make any catastrophic changes. Look at this example:
CREATE TABLE SOURCE_HIST -- Create history table
AS SELECT SYSDATE CHANGE_DATE, ALL_SOURCE.*
FROM ALL_SOURCE WHERE 1=2;
CREATE OR REPLACE TRIGGER change_hist -- Store code in hist table
AFTER CREATE ON SCOTT.SCHEMA -- Change SCOTT to your schema name
DECLARE
BEGIN
IF ORA_DICT_OBJ_TYPE in ('PROCEDURE', 'FUNCTION',
'PACKAGE', 'PACKAGE BODY',
'TYPE', 'TYPE BODY')
THEN
-- Store old code in SOURCE_HIST table
INSERT INTO SOURCE_HIST
SELECT sysdate, all_source.* FROM ALL_SOURCE
WHERE TYPE = ORA_DICT_OBJ_TYPE -- DICTIONARY_OBJ_TYPE IN 8i
AND NAME = ORA_DICT_OBJ_NAME; -- DICTIONARY_OBJ_NAME IN 8i
END IF;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20000, SQLERRM);
END;
/
show errors
A better approach is to create an external CVS or SVN repository for the scripts that install the PL/SQL code. The canonical version of what's in the database must match the latest CVS/SVN version or else someone would be cheating.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/35489/viewspace-688164/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 使用PL/Scope分析PL/SQL程式碼SQL
- SQL指令碼建立trigger,owner用變數出錯。SQL指令碼變數
- PL/SQL開發記錄SQL
- pl/sql記錄型別SQL型別
- pl/sql記錄表(一)SQL
- SQLite建立觸發器 CREATE TRIGGERSQLite觸發器
- PL/SQL 05 儲存過程 procedureSQL儲存過程
- DB2 PL/SQL Example: Sleep ProcedureDB2SQL
- PLSQL Language Referenc-PL/SQL集合和記錄-使用記錄更新行SQL
- 使用SQLServerAudit記錄資料庫變更SQLServer資料庫
- PL/SQL 07 觸發器 triggerSQL觸發器
- 加密PL/SQL程式碼加密SQL
- PLSQL Language Referenc-PL/SQL集合和記錄-可變陣列-正確地使用可變陣列SQL陣列
- SQL 建立儲存過程PROCEDURESQL儲存過程
- Git 碼雲--建立和使用記錄Git
- 用PL/SQL建立包SQL
- Oracle PL/SQL編寫PL/SQL程式碼的注意事項OracleSQL
- Procedure to create Distribution model
- PL/SQL變數值可變在程式中會變嗎?SQL變數
- oracle procedure儲存過程(pl/sql)_使用declare cursor_begin end巢狀Oracle儲存過程SQL巢狀
- 【PL/SQL】oracle建立dblinkSQLOracle
- 使用DBMS_HPROF評測PL/SQL程式碼效能(上)SQL
- PLSQL Language Referenc-PL/SQL靜態SQL-游標變數-建立游標變數SQL變數
- 記錄Record、PL/SQL表和二維陣列SQL陣列
- 保護你的 PL/SQL 程式碼!SQL
- MAKT 物料組 變更記錄表
- PL/SQL變數作用域SQL變數
- TEMPORARY LOBS are not freed up automatically after PL/SQL block executionSQLBloC
- PLSQL Language Referenc-PL/SQL集合和記錄-記錄更新和插入的限制SQL
- 設定PL/SQL Developer記住使用者名稱密碼SQLDeveloper密碼
- Create a trigger TO monitoring DDL
- PLSQL Language Referenc-PL/SQL集合和記錄-記錄比較-將記錄插入到表中SQL
- PL/SQl Developer使用SQLDeveloper
- PL/SQL Developer 使用SQLDeveloper
- Oracle PL/SQL程式碼中的註釋OracleSQL
- PL/SQL 01 程式碼編寫規則SQL
- 關於pl/sql的程式碼保護SQL
- Android Q 新特性及變更記錄Android