http://blog.chinaunix.net/u/21806/showart_484745.html
动态SQL中using的用法
关键字:oracle using 返回结果集
CREATE OR REPLACE PROCEDURE tP_JCXX_SECOND(CUR_RESULT OUT sys_refcursor,
TJFS IN VARCHAR2,--统计方式
NSPQ IN VARCHAR2,--片区
NSRZT IN VARCHAR2,--纳税人状态
XXHD IN VARCHAR2,--信息核定
NSRDZDAH IN VARCHAR2,--计算机代码
NSRMC IN VARCHAR2,--纳税人名称
SGY IN VARCHAR2--税管员
) IS
SQL_STATEMENT VARCHAR2(2000);
SQL_STATEMENT1 VARCHAR2(2000);
SQL_STATEMENT2 VARCHAR2(2000);
BEGIN
SQL_STATEMENT1:=
'SELECT A.NSRDZDAH JSJDM,--计算机代码
A.NSRMC NSRMC,--纳税人名称
E.ZCZB ZCZJ,--注册资金
F.HYMX_MC HY,--行业
G.DJZCLX_MC DJZCLX,--登记注册类型
A.SCJYDZ JYDZ,--经营地址
E.SCJYD_DHHM JYDZDH,--经营地址电话
H.NSRZT_MC NSRZT,--纳税人状态
A.GDGGBZ GGH,--是否是共管户
I.SWJG_MC SWJG,--税务机关
J.CZRY_MC SGY--税管员
FROM GY_NSRXX A,HD_NSR_HDXX B,GL_PQ_NSR C,DM_HDXL D,GY_NSRXX_KZ E,
DM_HYMX F,DM_DJZCLX G,DM_NSRZT H,DM_SWJG I,DM_CZRY J
WHERE A.NSRDZDAH=B.NSRDZDAH
AND A.NSRDZDAH=C.NSRDZDAH
AND B.HDXL_DM=D.HDXL_DM
AND A.NSRDZDAH=B.NSRDZDAH
AND A.HYMX_DM=F.HYMX_DM
AND A.DJZCLX_DM=G.DJZCLX_DM
AND A.NSRZT_DM=H.NSRZT_DM
AND A.SWJG_DM=I.SWJG_DM
AND A.ZGSWRY_DM=J.CZRY_DM
AND C.PQ_DM IN (NVL(:NSPQ,C.PQ_DM))
AND B.HDXL_DM IN (NVL(:XXHD,B.HDXL_DM))
AND A.NSRZT_DM IN (NVL(:NSRZT,A.NSRZT_DM))
AND A.NSRDZDAH IN (NVL(:NSRDZDAH,A.NSRDZDAH))
AND A.ZGSWRY_DM IN (NVL(:SGY,A.ZGSWRY_DM))';
SQL_STATEMENT2:='AND B.HDXL_DM LIKE SUBSTR(:TJFS,2)'||'%';
IF(SUBSTR(TJFS,1,2)='03') THEN
SQL_STATEMENT:=SQL_STATEMENT1||SQL_STATEMENT2;
OPEN CUR_RESULT FOR
SQL_STATEMENT using NSPQ,XXHD,NSRZT,NSRDZDAH,SGY,TJFS;
ELSE
SQL_STATEMENT:=SQL_STATEMENT1;
OPEN CUR_RESULT FOR
SQL_STATEMENT using in NSPQ, in XXHD, in NSRZT,in NSRDZDAH,in SGY;
END IF;
--DBMS_OUTPUT.Put(SQL_STATEMENT);
END tP_JCXX_SECOND;