3

我想编写一个程序,根据表中给出的数据用文本替换每个特定的字母。

create table jap (
alpha varchar2(1),
conv varchar2(5)
);

insert into jap(alpha,conv) values ( 'A' , 'ka' );
insert into jap(alpha,conv) values ( 'B' , 'tu' );
insert into jap(alpha,conv) values ( 'C' , 'mi' );
insert into jap(alpha,conv) values ( 'D' , 'te' );
insert into jap(alpha,conv) values ( 'E' , 'ku' );
insert into jap(alpha,conv) values ( 'F' , 'lu' );
insert into jap(alpha,conv) values ( 'G' , 'ji' );

例如,输入DEC应该导致输出tekumi

4

1 回答 1

5

试试这个:

SELECT xmlagg(xmlelement(e, conv)
              ORDER BY l).extract('//text()') .getstringval()
FROM
  (SELECT DISTINCT LEVEL l,
                         substr('DEC', LEVEL, 1) letter
   FROM dual CONNECT BY LEVEL <= length('DEC'))
INNER JOIN jap ON alpha = letter
ORDER BY l ;

是一个小提琴

于 2012-06-14T09:55:23.113 回答