不使用PL/SQL,是否可以在SELECT語句中執行數據屏蔽?Oracle SQL select語句中的數據屏蔽
例如:
(AS-IS)SELECT 'this is a string' from DUAL;
這是一個字符串
(TO-BE)SELECT 'this is a string' from DUAL;
XXXX XX X XXXXXX
不使用PL/SQL,是否可以在SELECT語句中執行數據屏蔽?Oracle SQL select語句中的數據屏蔽
例如:
(AS-IS)SELECT 'this is a string' from DUAL;
這是一個字符串
(TO-BE)SELECT 'this is a string' from DUAL;
XXXX XX X XXXXXX
REGEXP_REPLACE
可以這樣做:
SELECT REGEXP_REPLACE('this is a string', '\w', 'x') FROM DUAL;
這將替換所有非空白字符與x
。若要只替換字母,請嘗試以下操作:
SELECT REGEXP_REPLACE('this is a string', '[A-Za-z]', 'x') FROM DUAL;
您可以按如下方式創建用戶定義的函數,並在查詢中調用該函數來屏蔽數據。
create or replace function scrubbing(word in varchar2)
return varchar2
as
each_var char(2);
final_val varchar2(100);
complete_data varchar2(4000);
each_word varchar2(1000);
cursor val is select substr(replace(word,' ','#'),-level,1) from dual connect by level<=length(word);
begin
open val;
--final_val:= '';
loop
fetch val into each_var;
exit when val%NOTFOUND;
--dbms_output.put_line(each_var);
final_val := trim(final_val)||trim(each_var);
--dbms_output.put_line(final_val);
select regexp_substr(final_val,'[A-Za-z]+') into each_word from dual;
select replace(translate(final_val,each_word,dbms_random.string('L',length(word))),'#',' ') into complete_data from dual;
end loop;
return complete_data;
end;
PLease更具體。 – OldProgrammer