sql语句

本文详细解析了SQL查询语句的正确用法,包括使用自定义函数提高查询效率的方法,并对比了错误的查询方式,强调了正确语法的重要性。同时,介绍了如何通过自定义函数f_get_dicmc获取字典项描述,优化查询过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

正确:select t.*, f_get_dicmc('RYLB_SJBD',t.rylx  ) as rylx  
from t_tjfx_syrk_sjbdb t where t.sjly='1' and t.batchno='33238ED6-0E3D-4275-9B5B-33F46FD792AA'  order by t.xh;

create or replace function f_get_dicmc(v_zdlb varchar2,v_dm varchar2)
return varchar2
as
   v_mc varchar2(250);
begin
    select MC into v_mc from t_common_dictionary where zdlb=v_zdlb and dm=v_dm;
    return v_mc;
end;

 

错误:select XH as xh,SFZH as sfzh,XM as xm,XB as xb,MZ as mz, 
        (select mc from t_common_dictionary where zdlb ='RYLB_SJBD' 
        #if($rylx && !$rylx.equals(""))
                and dm = #[rylx]
        #end  ) as rylx,
        HJDQH as hjdqh,HJDXZ as hjdxz,
        DJDWDM as djdwdm,DJDWMC as djdwmc,
        DJRXM as djrxm,DJSJ as djsj,SJBDSJ as sjbdsj
        from t_tjfx_syrk_sjbdb where 1=1
        #if($batchno && !$batchno.equals(""))
                and batchno = #[batchno]
        #end 
        #if($sjly && !$sjly.equals(""))
                and sjly = #[sjly]
        #end
        order by xh 

 

 

insert into t_common_dictionary values('11800452','RYLB_SJBD','人员类别_数据比对','1','常住人口','','','1',null);
insert into t_common_dictionary values('11800453','RYLB_SJBD','人员类别_数据比对','2','流动人口','','','1',null);
insert into t_common_dictionary values('11800454','RYLB_SJBD','人员类别_数据比对','5','寄住人口','','','1',null);
insert into t_common_dictionary values('11800455','RYLB_SJBD','人员类别_数据比对','6','从业人员','','','1',null);
insert into t_common_dictionary values('11800456','RYLB_SJBD','人员类别_数据比对','7','就学人员','','','1',null);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值