этот sp был написан для SQL Server и затем «преобразован» для использования в Oracle. но приложение не работает из-за типа данных, возвращаемых Oracle, а MSSQL отличается.
Как мне настроить этот sp так, чтобы он возвращал данные, приемлемые для Oracle?
DECLARE
CNT PLS_INTEGER;
BEGIN
SELECT COUNT(*)
INTO CNT
FROM OEN.DBD_C_MODULES;
IF CNT > 0 THEN
INSERT INTO OEN.DBD_C_MODULES (MODULE_ID, DESCRIPTION, ACTIVE) VALUES (11, 'Medi', 1);
INSERT INTO OEN.DBD_C_MODULES (MODULE_ID, DESCRIPTION, ACTIVE) VALUES (15, 'Orde', 1);
COMMIT;
END IF;
END;
/
CREATE OR REPLACE PROCEDURE OEN.DBD_GET_MEDICINE (
FACILITYKEY VARCHAR2
, DATEFROM DATE
, DATETHRU DATE
, UNITSTR VARCHAR2
, INCLUDEDISCH NUMERIC
, PATNUMBER NUMERIC
, MEDNAME VARCHAR2
, OCURSOR OUT SYS_REFCURSOR
)
AS
BEGIN
OPEN OCURSOR FOR
SELECT DTR.DATE_ORDER "Date"
, COUNT(*) "Count"
FROM ( ( ( ( (
SELECT TRUNC(DATEFROM) + ROWNUM DATE_ORDER, ROWNUM + 1 DAY_ORDER FROM OEN.GEN_C_DX WHERE ROWNUM <= DATETHRU - DATEFROM
) DTR
INNER JOIN OPTC.ORD_M_ADMIN AM ON DTR.DATE_ORDER + ( AM.ADMIN_TIME - TRUNC(AM.ADMIN_TIME) ) BETWEEN AM.START_DATE AND AM.END_DATE
)
LEFT OUTER JOIN OPTC.ORD_D_ADMIN_LOG AL ON AM.ORDER_KEY = AL.ORDER_KEY
)
LEFT OUTER JOIN OPTC.ORD_C_ADMIN_RESULT AR ON AL.ADMIN_RESULT = AR.RESULT_KEY
)
INNER JOIN OGEN.GEN_M_PATIENT_MAST M ON AM.PAT_NUMBER = M.PAT_NUMBER AND AM.FACILITY_KEY = M.FACILITY_KEY AND ( UNITSTR IS NULL OR MOD(INSTR(UNITSTR, M.UNIT_CODE), 2) = 1 )
)
LEFT OUTER JOIN OGEN.GEN_M_DOCTOR_MAST DR ON M.PRIMARY_DOCTOR_KEY = DR.DOCTOR_KEY AND M.FACILITY_KEY = DR.FACILITY_KEY
WHERE AM.FACILITY_KEY IN (SELECT * FROM TABLE(OGEN.COMMA_TO_TABLE(FACILITYKEY)))
AND ( AM.PAT_NUMBER = PATNUMBER OR PATNUMBER = -1 )
AND ( MEDNAME IS NULL OR AM.ORDER_NAME LIKE ( '%' || MEDNAME || '%' ) )
AND AM.PRN = 0
AND OPTC.ORD_IS_ADMIN(AM.START_DATE, DTR.DATE_ORDER, AM.DAYS_REQ) = 1
AND NOT EXISTS ( SELECT AL1.ORDER_KEY
FROM OPTC.ORD_D_ADMIN_LOG AL1
WHERE AL1.ORDER_KEY = AM.ORDER_KEY
AND INSTR('01234', CAST(ABS(AL1.ADMIN_RESULT) AS VARCHAR2(2))) > 0 )
AND NOT EXISTS ( SELECT OM.ORDER_KEY
FROM OPC.ORD_M_ORDER OM
WHERE OM.ORDER_STATUS = 0
AND OM.HOLD_ON_FROM = AM.ORDER_KEY
AND DTR.DATE_ORDER BETWEEN OM.START_DATE AND OM.END_DATE )
AND ( ( INCLUDEDISCH = 0 ) OR ( 1 = ( CASE WHEN ( INCLUDEDISCH = 1 ) AND M.DISCHARGE_DATE IS NULL THEN 1 WHEN ( INCLUDEDISCH = 2 ) AND ( M.DISCHARGE_DATE IS NOT NULL ) THEN 1 ELSE 0 END ) ) )
GROUP BY DTR.DATE_ORDER;
END;