我有一个查询,我用它来显示前端的数据。问题是,如果我使用简单参数运行并且它获取数据,则查询工作正常,但是当通过存储过程运行相同时,它不会带来任何数据。
以下是简单查询:
SELECT DISTINCT NVL(STM.SERVICE_TYPE,'-')SERVICETYPE, NVL(SM.SERVICE_NAME,'-')SERVICENAME, NVL(SM.URL,'-')URL, NVL(SM.MXD,'-')MXD, NVL(SD.SERVER_TYPE,'-')SERVERTYPE, NVL(SD.LAYER,'-')LAYER
FROM SERVICES_MASTER SM
INNER JOIN SERVICE_DETAILS SD
ON SM.SERVICE_ID = SD.SERVICE_ID
INNER JOIN SERVICE_TYPES_MASTER STM
ON SM.SERVICE_TYPE_ID = STM.SERVICE_TYPE_ID
WHERE SM.SERVICE_NAME LIKE '%SNOCAlarmBoundary%';
以下是存储过程
STREX:='SELECT DISTINCT NVL(STM.SERVICE_TYPE,''-'')SERVICETYPE, NVL(SM.SERVICE_NAME,''-'')SERVICENAME, NVL(SM.URL,''-'')URL, NVL(SM.MXD,''-'')MXD, NVL(SD.SERVER_TYPE,''-'')SERVERTYPE, NVL(SD.LAYER,''-'')LAYER
FROM SERVICES_MASTER SM
INNER JOIN SERVICE_DETAILS SD
ON SM.SERVICE_ID = SD.SERVICE_ID
INNER JOIN SERVICE_TYPES_MASTER STM
ON SM.SERVICE_TYPE_ID = STM.SERVICE_TYPE_ID
WHERE SM.'|| UPPER(P_PARAM_TYPE) ||' '|| P_OPERATOR || ' :PARAM';
DBMS_OUTPUT.PUT_LINE('STREX '|| STREX);
OPEN P_RETURN FOR STREX USING VAL;
为什么它不适用于第二种情况,我应该怎么做呢
更新
PROCEDURE FILTER_SEARCH_DATA
(
P_SEARCH_TYPE IN NVARCHAR2,
P_PARAM_TYPE IN NVARCHAR2,
P_OPERATOR IN NVARCHAR2,
P_TEXTVAL IN NVARCHAR2,
P_RETURN OUT SYS_REFCURSOR
)
AS
STR NVARCHAR2(400):='';
STROP NVARCHAR2(400):='';
STREX VARCHAR2(4000):='';
VAL NVARCHAR2(4000);
BEGIN
IF (P_OPERATOR = 'LIKE') THEN
val := '%' || UPPER(P_TEXTVAL) ||'%';
ELSE
val := UPPER(P_TEXTVAL) ;
END IF;
DBMS_OUTPUT.PUT_LINE('STR'|| STR);
IF P_SEARCH_TYPE = 'Application' THEN
STREX:='SELECT DISTINCT NVL(AM.APPLICATIONNAME,''-'')APPLICATIONNAME, NVL(AD.URLPATH,''-'')URL, NVL(AM.PROJECTNO,''-'')PROJECTNO, NVL(AM.VSS_FOLDER_LOC,''-'')VSSFOLDERLOC,
NVL(AU.NAME, ''-'')SPOCUSER, NVL(AUR.NAME,''-'')REQUESTEDBY, NVL(AUD.NAME,''-'')DELIVERYMANAGER
FROM APPLICATION_MASTER AM
INNER JOIN APPLICATION_DETAILS AD
ON AM.APP_MST_ID = AD.APP_MST_ID
INNER JOIN APPUSER_UMS AU
ON AM.APP_MST_ID = AU.APP_USERID
INNER JOIN APPUSER_UMS AUR
ON AUR.APP_USERID = AM.REQUESTED_BY_APPUSRID
INNER JOIN APPUSER_UMS AUD
ON AUD.APP_USERID = AM.DELIVERY_MANAGER_APPUSRID
WHERE AM.'|| UPPER(P_PARAM_TYPE) ||' '|| P_OPERATOR || ' :PARAM';
DBMS_OUTPUT.PUT_LINE('STREX '|| STREX);
OPEN P_RETURN FOR STREX USING VAL;
END IF;
IF P_SEARCH_TYPE = 'Services' THEN
STREX:='SELECT DISTINCT NVL(STM.SERVICE_TYPE,''-'')SERVICETYPE, NVL(SM.SERVICE_NAME,''-'')SERVICENAME, NVL(SM.URL,''-'')URL, NVL(SM.MXD,''-'')MXD, NVL(SD.SERVER_TYPE,''-'')SERVERTYPE, NVL(SD.LAYER,''-'')LAYER
FROM SERVICES_MASTER SM
INNER JOIN SERVICE_DETAILS SD
ON SM.SERVICE_ID = SD.SERVICE_ID
INNER JOIN SERVICE_TYPES_MASTER STM
ON SM.SERVICE_TYPE_ID = STM.SERVICE_TYPE_ID
WHERE SM.'|| UPPER(P_PARAM_TYPE) ||' '|| P_OPERATOR || ' :PARAM';
DBMS_OUTPUT.PUT_LINE('STREX '|| STREX);
OPEN P_RETURN FOR STREX USING VAL;
END IF;
IF P_SEARCH_TYPE = 'Layers' THEN
STREX:='SELECT NVL(SERVER_TYPE,''-'')SERVERTYPE, NVL(LAYER,''-'')LAYER,
NVL(FEATURECLASS,''-'')FEATURECLASS
FROM SERVICE_DETAILS
WHERE '|| UPPER(P_PARAM_TYPE) ||' '|| P_OPERATOR || ' :PARAM';
DBMS_OUTPUT.PUT_LINE('STREX '|| STREX);
OPEN P_RETURN FOR STREX USING VAL;
END IF;
IF P_SEARCH_TYPE = 'Dbitem' THEN
STREX:='SELECT NVL(DM.DB_ITEMNAME,''-'')DBITEMNAME, NVL(DM.SCHEMAOWNER,''-'')SCHEMAOWNER, NVL(DT.DBITEMTYPE,''-'')DBITEMTYPE
FROM DATABASE_ITEMMASTER DM
INNER JOIN DBITEMTYPE DT
ON DM.DB_ITM_ID = DT.DB_ITEMTYPE_ID
WHERE DM.'|| UPPER(P_PARAM_TYPE) ||' '|| P_OPERATOR || ' :PARAM';
DBMS_OUTPUT.PUT_LINE('STREX '|| STREX);
OPEN P_RETURN FOR STREX USING VAL;
END IF;
END FILTER_SEARCH_DATA;
答案 0 :(得分:3)
好的,所以这里只是一个狂野的猜测
(正如我之前提到的 - 我们没有足够的信息来安全地找出问题的根源)。
请尝试以下:
IF P_SEARCH_TYPE = 'Services' THEN
STREX:='SELECT DISTINCT NVL(STM.SERVICE_TYPE,''-'')SERVICETYPE, NVL(SM.SERVICE_NAME,''-'')SERVICENAME, NVL(SM.URL,''-'')URL, NVL(SM.MXD,''-'')MXD, NVL(SD.SERVER_TYPE,''-'')SERVERTYPE, NVL(SD.LAYER,''-'')LAYER
FROM SERVICES_MASTER SM
INNER JOIN SERVICE_DETAILS SD
ON SM.SERVICE_ID = SD.SERVICE_ID
INNER JOIN SERVICE_TYPES_MASTER STM
ON SM.SERVICE_TYPE_ID = STM.SERVICE_TYPE_ID
WHERE UPPER(SM.'|| P_PARAM_TYPE || ') ' || P_OPERATOR || ' :PARAM';
所以我改变的是现在upper
是查询字符串的一部分。
我猜,这是你的初衷(因为val
总是大写)。