oracle 繁體轉換為簡體


今天公司要求做國際化,Struts2的國際化可以在配置文件里面進行配置,但是數據庫里面存儲的卻無從下手,請教了一位同事,給了一個存儲過程,可以大部分實現,貌似不錯,介紹如下:

 

 

存儲過程如下:

CREATE OR REPLACE FUNCTION GYIC_NEW.TRANS_CHINESE (p_inputStr IN VARCHAR2, p_inputType IN NUMBER) RETURN VARCHAR2
IS
v_ret VARCHAR2(300) := '';
i INT := 0;
v_str VARCHAR2(3);
v_count INT := 0;
/******************************************************************************
NAME: transform_chinese
PURPOSE:
PARAMETERS: p_inputType = 0 ==> simple chinese transform to tradition chinese
p_inputType = 1 ==> tradition chinese transform to simple chinese

REVISIONS:
Ver Date Author Description
--------- ---------- --------------- ------------------------------------
1.0 2012/6/5 1. Created this function.

NOTES:

Automatically available Auto Replace Keywords:
Object Name: transform_chinese
Sysdate: 2012/6/5
Date and Time: 2012/6/5, 上午 10:29:10, and 2012/6/5 上午 10:29:10
Username: (set in TOAD Options, Procedure Editor)
Table Name: (set in the "New PL/SQL Object" dialog)

******************************************************************************/
BEGIN
if p_inputStr is null or p_inputStr = '' then
return null;
end if;

if p_inputType = 0 then
for i in 1.. length(p_inputStr)
loop
select count(*) into v_count from chineseword where simpleword = substr(p_inputStr, i, 1);
if v_count > 0 then
select traditionword into v_str from chineseword where simpleword = substr(p_inputStr, i, 1);

v_ret := v_ret || v_str;
else
v_ret := v_ret || substr(p_inputStr, i, 1);
end if;
end loop;
else
for i in 1.. length(p_inputStr)
loop
select count(*) into v_count from chineseword where traditionword = substr(p_inputStr, i, 1);
if v_count > 0 then
select simpleword into v_str from chineseword where traditionword = substr(p_inputStr, i, 1);

v_ret := v_ret || v_str;
else
v_ret := v_ret || substr(p_inputStr, i, 1);
end if;
end loop;
end if;
RETURN v_ret;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END TRANS_CHINESE;

 

存在chineseword表,里面有兩個字段,simpleword表示簡體的字段,traditionword表示繁體的字段,有的繁體可能寫出來,建表和插入的sql如下:

建表:

-- Create table
create table GYIC_NEW.CHINESEWORD
(
simpleword VARCHAR2(2000),
traditionword VARCHAR2(2000)
)
tablespace USERS
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64
minextents 1
maxextents unlimited
);

數據太大了,也不可以上傳附件,就不上傳了

使用方法如下:

首先找你要轉換的表的字段,例如我這里是AA表下面name這個字段存儲的是繁體,需要轉換為簡體:

update aa set name = trans_chinese(name, 1) ;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM