2011-11-21 50 views
0

此sp是爲SQL Server編寫的,然後「轉換」爲Oracle使用。但該應用程序由於Oracle返回的數據類型而導致失敗,並且MSSQL不同。 如何調整此sp以返回Oracle可接受的數據?定義爲NUMERICOracle sp不能使用數據整數

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('', 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; 
+4

你能解釋一下什麼是失敗?你是否遇到Oracle錯誤?如果是這樣,有什麼錯誤?什麼線?這是一個編譯錯誤?還是運行時錯誤?如果你知道這是一個數據類型錯誤,問題是哪一列?應用程序期望什麼數據類型? –

+0

有兩個問題。哪個給出了錯誤?另外,這兩個代碼塊是如何相關的?該過程不在匿名plsql塊中使用。 – GolezTrol

+1

我認爲'pls_integer'應該只是'整數'。 – GolezTrol

回答

1

你的輸入參數應該是NUMBER例如:

CREATE OR REPLACE PROCEDURE OEN.DBD_GET_MEDICINE (
    FACILITYKEY IN VARCHAR2, 
    DATEFROM  IN DATE, 
    DATETHRU  IN DATE, 
    UNITSTR  IN VARCHAR2, 
    INCLUDEDISCH IN NUMBER, 
    PATNUMBER IN NUMBER, 
    MEDNAME  IN VARCHAR2, 
    OCURSOR  OUT SYS_REFCURSOR 
) 
+0

這一點是失敗的: – Booksman

+0

@Booksman什麼是失敗? – wweicker

+0

現在不行,謝謝你的協助。上帝祝福你。 – Booksman