create or replace package body CRF_CMS_DOCTOR_PKG is
--根据医院查询医生
PROCEDURE P_HOSPITALBYDOCTOR_LIST
(
v_HOSPITAL_ID IN NUMERIC,
v_DEPT_ID IN NUMERIC,
v_JOBTITLE_ID IN NUMERIC,
v_USER_NAME IN VARCHAR2,
v_MOBILE IN VARCHAR2,
v_DIMDOCTOR_LIST OUT DOCTDRSOR
)
IS
v_SQL VARCHAR2(256);
v_Where VARCHAR2(256);
v_StrEnd VARCHAR2(16);
v_Length NUMBER(8);
BEGIN
--v_SQL:='SELECT USER_NAME,MOBILE,SEX,HOSPITAL_ID,DEPT_ID,JOBTITLE_ID,CREATE_TIME,UPDATE_USER_ID FROM T_DOCTOR_INFO WHERE HOSPITAL_ID like ''%';
v_SQL:='SELECT USER_NAME,MOBILE,SEX,HOSPITAL_ID,DEPT_ID,JOBTITLE_ID,CREATE_TIME,INTRODUCE FROM T_DOCTOR_INFO ';
v_Where:='WHERE ';
IF v_HOSPITAL_ID>0 THEN
v_Where:=v_Where||'HOSPITAL_ID='||TO_CHAR(v_HOSPITAL_ID);
v_Where:=v_Where||' AND';
END IF;
IF v_DEPT_ID>0 THEN
v_Where:=v_Where||' DEPT_ID='||TO_CHAR(v_DEPT_ID);
v_Where:=v_Where||' AND';
END IF;
IF v_JOBTITLE_ID>0 THEN
v_Where:=v_Where||' JOBTITLE_ID='||TO_CHAR(v_JOBTITLE_ID);
v_Where:=v_Where||' AND';
END IF;
IF v_MOBILE<>'00000000000' THEN
v_Where:=v_Where||' MOBILE LIKE ';
v_Where:=v_Where||'''%';
v_Where:=v_Where||v_MOBILE;
v_Where:=v_Where||'%''';
v_Where:=v_Where||' AND';
END IF;
IF v_USER_NAME<>'aaaaaaaaaa' THEN
v_Where:=v_Where||' USER_NAME LIKE ';
v_Where:=v_Where||'''%';
v_Where:=v_Where||v_USER_NAME;
v_Where:=v_Where||'%''';
END IF;
v_Length:=length(v_Where);
v_StrEnd:=substr(v_Where,v_Length-2);
IF v_StrEnd='AND' THEN
v_Where:=substr(v_Where,0,v_Length-4);
END IF;
v_Length:=length(v_Where);
v_SQL:=v_SQL||v_Where;
OPEN v_DIMDOCTOR_LIST FOR v_SQL;
--select * from T_DOCTOR_INFO where HOSPITAL_ID like '%%';
end P_HOSPITALBYDOCTOR_LIST;
end CRF_CMS_DOCTOR_PKG;
注意:要想在存储过程中判断传过来的字符串是否为空,可以写成
IF v_MOBILE not null THEN .....