可以使用动态的sql语句
declare
col varhcar2(200);
str varhcar2(200);
begin
col='B1';
str='select * from 字典表 where '||col||'=lbdm';
execute immediate str;
end;
col可以用作参数的插入,可以用存储过程实现。
declare
col varhcar2(200);
str varhcar2(200);
begin
col='B1';
str='select * from 字典表 where '||col||'=lbdm';
execute immediate str;
end;
col可以用作参数的插入,可以用存储过程实现。
A1 B1 C1 D1 E1
01 苹果 牙膏 电锅 001
02 蜜桃 牙刷 电风扇 002
(select lbmc from 字典表 where 字典表.lbid=主表.C1)C1,
(select lbmc from 字典表 where 字典表.lbid=主表.D1)D1 ,E1 FROM 主表
from 主表 a,
(select m.a1,d.lbmc from 字典表 d,主表 m where m.b1=d.ldid and d.ldbm=1) b,
(select m.a1,d.lbmc from 字典表 d,主表 m where m.b1=d.ldid and d.ldbm=2) c,
(select m.a1,d.lbmc from 字典表 d,主表 m where m.b1=d.ldid and d.ldbm=3) d
where (a.a1=b.a1 and a.a1=c.a1 and a.a1=d.a1)
create or replace function f_bm(as_bm in varchar2)return varchar2 is
v_mc varchar2(20);
begin
select lbmc into v_mc from 编码表;
return v_mc;
exception
when others them
return as_bm;
end;
调用函数
select f_bm(ldbm) from 主表