- 論壇徽章:
- 0
|
通過觸發(fā)器 獲取 DDL語句,如果獲取的內(nèi)容中包含中文,就會導(dǎo)致 出現(xiàn)亂碼,示例如下:- ---- 存儲DDL語句的表
- create table sys.test_audit_ddl
- (opertime date,
- operation varchar2(30),
- object_type varchar2(30),
- object_name varchar2(30),
- sql_stmt varchar2(4000)
- );
- ---- 捕獲DDL語句的觸發(fā)器
- create or replace trigger sys.test_trg_audit_ddl
- before ddl on database
- declare
- pragma autonomous_transaction;
- n number;
- stmt varchar2(4000) :=null;
- sql_text ora_name_list_t;
- begin
- n := ora_sql_txt(sql_text);
- for i in 1..n loop
- stmt := stmt || sql_text(i);
- end loop;
- insert into sys.test_audit_ddl
- (
- opertime,operation,
- object_type,object_name,sql_stmt
- )
- values(
- sysdate,
- ora_sysevent,
- ora_dict_obj_type,
- ora_dict_obj_name,
- stmt
- );
- commit;
- end;
- /
- ---- 測試DDL捕獲亂碼的情形
- create or replace procedure test_proc as
- begin
- -- 這是一個測試中文DDL是否亂碼的例子
- dbms_output.put_line('這是一個測試中文DDL是否亂碼的過程');
- end;
- /
- create or replace procedure test_proc as
- begin
- --------------- 這是一個測試中文DDL是否亂碼的例子
- dbms_output.put_line('這是一個測試中文DDL是否亂碼的過程');
- end;
- /
復(fù)制代碼 結(jié)果如下:- 14:36:11 SQL> select * from sys.test_audit_ddl;
- OPERTIME OPERATION OBJECT_TYPE
- ------------------- ------------------------------ ------------------------------
- OBJECT_NAME
- ----------------------------------------
- SQL_STMT
- ---------------------------------------------------------------------------------------------------
- 2012-06-26 14:36:02 CREATE PROCEDURE
- TEST_PROC
- create or replace procedure test_proc as
- begin
- -- 這是一個測試中文DDL是否亂碼的例子
- dbms_output.put_line('這是一個測試中文DDL是否亂碼的過程');
- end;
- 2012-06-26 14:36:11 CREATE PROCEDURE
- TEST_PROC
- create or replace procedure test_proc as
- begin
- --------------- 這是一個測試中文DDL是否亂碼的例子
- dbms_output.put_line('這是桓霾饈災(zāi)形腄DL是否亂碼的過程');
- end;
復(fù)制代碼 以上示例代碼是從其他帖子 復(fù)制來的,不過和我遇到的問題是一摸一樣的,自己也進(jìn)行了驗證,故就直接采用了。
(沒有權(quán)限寫URL地址,故沒有貼出)
數(shù)據(jù)庫版本:10.2.0.5
我的想法是 中文是占2個字符的,而在 dbms_standard.ora_name_list_t 這個函數(shù)將 獲取的 內(nèi)容 進(jìn)行分割的時候,將一個中文給分割了,就導(dǎo)致分割之后的中文內(nèi)容全部是亂碼,
不知道有沒有辦法解決呢?? |
|