CREATE TABLE XYG.XYG_chinese_Spell(
chinese_Spell_ID NUMBER NOT NULL,--表格ID
chinese_Spell VARCHAR2(50) NOT NULL, -- 汉语拼音
chinese_Word VARCHAR2(4000) NOT NULL -- 汉字堆
---5 who
,CREATED_BY NUMBER DEFAULT -1 NOT NULL --创建者
,CREATION_DATE DATE DEFAULT SYSDATE NOT NULL --创建日期
,LAST_UPDATED_BY NUMBER DEFAULT -1NOT NULL --最后更新人
,LAST_UPDATE_DATE DATE DEFAULT SYSDATE NOT NULL --最后更新日期
,LAST_UPDATE_LOGIN NUMBER DEFAULT -1NOT NULL --最后登陆人
,ATTRIBUTE_CATEGORY VARCHAR2(30)
,ATTRIBUTE1 VARCHAR2(240)
,ATTRIBUTE2 VARCHAR2(240)
,ATTRIBUTE3 VARCHAR2(240)
,ATTRIBUTE4 VARCHAR2(240)
,ATTRIBUTE5 VARCHAR2(240)
,ATTRIBUTE6 VARCHAR2(240)
,ATTRIBUTE7 VARCHAR2(240)
,ATTRIBUTE8 VARCHAR2(240)
,ATTRIBUTE9 VARCHAR2(240)
,ATTRIBUTE10 VARCHAR2(240)
,ATTRIBUTE11 VARCHAR2(240)
,ATTRIBUTE12 VARCHAR2(240)
,ATTRIBUTE13 VARCHAR2(240)
,ATTRIBUTE14 VARCHAR2(240)
,ATTRIBUTE15 VARCHAR2(240)
,CONSTRAINT PK_chinese_Spell PRIMARY KEY(chinese_Spell_ID)
)
TABLESPACE XYG_DATA ;
COMMENT ON TABLE XYG.XYG_chinese_Spell IS 'XYG_汉字对应拼音';
CREATE SYNONYM APPS.XYG_chinese_Spell FOR XYG.XYG_chinese_Spell;
CREATE SEQUENCE XYG.XYG_chinese_Spell_S
NOMAXVALUE
MINVALUE 1;
--DROP SYNONYM APPS.XYG_chinese_Spell_S;
CREATE SYNONYM APPS.XYG_chinese_Spell_S FOR XYG.XYG_chinese_Spell_S;
CREATE UNIQUE INDEX XYG.XYG_chinese_Spell_U1
ON XYG.XYG_chinese_Spell(chinese_Word)
TABLESPACE XYG_IDX;
--DROP TABLE XYG_chinese_Spell_TEMP;
---创建临时表,要将Excel的数据导入到这个表格。
CREATE TABLE XYG_chinese_Spell_TEMP(
chinese_Spell VARCHAR2(500), -- 汉语拼音
chinese_Word VARCHAR2(4000) -- 汉字堆
);
SELECT * FROM XYG_chinese_Spell_TEMP;
---去掉分号
UPDATE XYG_chinese_Spell_TEMP
SET CHINESE_WORD = REPLACE(CHINESE_WORD,'''',NULL);
---去掉逗号
UPDATE XYG_chinese_Spell_TEMP
SET CHINESE_WORD = REPLACE(CHINESE_WORD,',',NULL);
---去掉空格
UPDATE XYG_chinese_Spell_TEMP
SET CHINESE_WORD = LTRIM(TRIM(CHINESE_WORD));
UPDATE XYG_chinese_Spell_TEMP
SET CHINESE_SPELL = LTRIM(TRIM(CHINESE_SPELL));
COMMIT;
---向正式表格塞入:
INSERT INTO XYG_chinese_Spell(chinese_Spell_ID,CHINESE_SPELL,CHINESE_WORD)
SELECT XYG_chinese_Spell_S.NEXTVAL
,CHINESE_SPELL
,CHINESE_WORD
FROM XYG_chinese_Spell_TEMP;
COMMIT;
SELECT * FROM XYG_chinese_Spell
WHERE CHINESE_WORD LIKE '%你%'
---检查数据没问题,则可以dorp掉临时表
DROP TABLE XYG_chinese_Spell_TEMP;
----接着建立函数:
---get_chinese_Spell ;函数内容下面有。
---注意函数的输入参数。可以任意输出想要的格式~
SELECT XYG_PUB_COMMON_PKG.get_chinese_Spell('我的文档','_','FULL','INITCAP','#',0) FROM DUAL
UPDATE XYG_chinese_Spell
SET CHINESE_WORD = REPLACE(CHINESE_WORD,'信',NULL)
WHERE chinese_Spell_ID = 450;
UPDATE XYG_chinese_Spell
SET CHINESE_WORD = REPLACE(CHINESE_WORD,'查',NULL)
WHERE chinese_Spell_ID IN (69,133);
UPDATE XYG_chinese_Spell
SET CHINESE_WORD = REPLACE(CHINESE_WORD,'掉',NULL)
WHERE chinese_Spell_ID IN (367);
UPDATE XYG_chinese_Spell
SET CHINESE_WORD = REPLACE(CHINESE_WORD,'数',NULL)
WHERE chinese_Spell_ID IN (461);
UPDATE XYG_chinese_Spell
SET CHINESE_WORD = REPLACE(CHINESE_WORD,'题',NULL)
WHERE chinese_Spell_ID IN (170);
UPDATE XYG_chinese_Spell
SET CHINESE_WORD = REPLACE(CHINESE_WORD,'精',NULL)
WHERE CHINESE_CODE_ID IN (407);
UPDATE XYG_chinese_Spell
SET CHINESE_WORD = REPLACE(CHINESE_WORD,'以',NULL)
WHERE chinese_Spell_ID IN (463);
--SELECT XYG_PUB_COMMON_PKG.get_chinese_Spell('我的文档(东镀囧)001','_','FULL','INITCAP','#',0) FROM DUAL
function get_chinese_Spell(p_cnStr In varchar2
,P_SEPARATOR In varchar2 Default Null--输出汉字的分隔符
,p_output_type In varchar2 Default Null--输出格式,是首字大写FIRST还是全部FULL
,P_CASE_TYPE IN VARCHAR2 DEFAULT 'LOWER'---输出汉字的拼音的格式,小写,大写还是首字母大写INITCAP。
,P_UNKNOW_SPELL VARCHAR2 DEFAULT '#'---识别不了的用哪个字符显示
,P_RAISE IN NUMBER DEFAULT XYG_PUB_CONST_PKG.C_TRUE) return varchar2
as
lv_spell varchar2(3000);
lv_temp Varchar2(100);
lv_char varchar2(100);
---
lv_exists_cn boolean;--是否存在汉字的
---获取单个的拼音
Function get_signle_spell(P_SIGNLE_CHINESE IN VARCHAR2) return VARCHAR2
is
l_return XYG_chinese_Spell.CHINESE_SPELL%TYPE;
begin
SELECT XCS1.CHINESE_SPELL
INTO l_return
FROM XYG_chinese_Spell XCS1
WHERE XCS1.CHINESE_Spell_ID =
(SELECT MAX(XCS2.CHINESE_Spell_ID)
FROM XYG_chinese_Spell XCS2
WHERE XCS2.CHINESE_WORD LIKE '%'||P_SIGNLE_CHINESE||'%');
RETURN l_return;
EXCEPTION
WHEN OTHERS THEN
RETURN P_UNKNOW_SPELL;
end;
begin
if p_cnStr is null then
return '';
end if;
lv_exists_cn := false;
for i In 1..length(p_cnStr) loop
lv_char:=substr(p_cnStr,i,1);
if lengthb(lv_char) = 1 then
if lv_exists_cn then
lv_spell:=lv_spell||P_SEPARATOR||lv_char;
lv_exists_cn := false;
else
lv_spell:=lv_spell||lv_char;
end if;
else--汉字:
----如果是常用的符号,也要转换。只是单对单的转换。
if lv_char = ',' then--逗号
lv_temp := ',';
elsif lv_char = '。' then--句号
lv_temp := '.';
elsif lv_char = '?' then--问号
lv_temp := '?';
elsif lv_char = '!' then--感叹号
lv_temp := '!';
elsif lv_char = '‘' then--单引号
lv_temp := '''';
elsif lv_char = '“' then--双引号
lv_temp := '"';
elsif lv_char = ';' then--分号
lv_temp := ';';
elsif lv_char = ':' then--冒号
lv_temp := ':';
else
lv_exists_cn := true;
lv_temp := get_signle_spell(lv_char);
IF P_CASE_TYPE = 'LOWER' THEN
lv_temp := LOWER(lv_temp);
ELSIF P_CASE_TYPE = 'UPPER' THEN
lv_temp := UPPER(lv_temp);
ELSIF P_CASE_TYPE = 'INITCAP' THEN
lv_temp := INITCAP(lv_temp);
ELSE
NULL;
END IF;
end if;
if p_output_type = 'FIRST' then
lv_spell:=lv_spell||P_SEPARATOR||substr(lv_temp,1,1);
else
lv_spell:=lv_spell||P_SEPARATOR||lv_temp;
end if;
end if;
end loop;
---将左边的分隔符去掉
IF P_SEPARATOR IS NOT NULL THEN
lv_spell := LTRIM(lv_spell,P_SEPARATOR);
END IF;
return lv_spell;
end;
来自:http://www.itpub.net/thread-1774405-1-8.html