2011-12-09 88 views
0

我有5個表,使用oracle過程如何從這五個表中獲取選定的列,並將所有行作爲簡單的選擇查詢返回,而無需連接。我寫了這個程序,但我無法得到慾望的結果。如何使用多個遊標從oracle過程中返回所有行

create or replace 
    PROCEDURE NOTIFICATIN_REPORT_TEST(
     para_claim_no IN VARCHAR2, 
     O_CRM_ACC_CAL_GARAGE out CRM_CLAIM_INT_DETAILS_VIEW.CRM_ACC_CAL_GARAGE%type, 
    O_CRM_ACC_DAM_COMP out CRM_CLAIM_INT_DETAILS_VIEW.CRM_ACC_DAM_COMP%type, 
    O_CRM_ACC_DATE_TIME out CRM_CLAIM_INT_DETAILS_VIEW.CRM_ACC_DATE_TIME%type, 
    O_CRM_ACC_DESC out CRM_CLAIM_INT_DETAILS_VIEW.CRM_ACC_DESC%type, 
    O_CRM_ACC_FIR out CRM_CLAIM_INT_DETAILS_VIEW.CRM_ACC_FIR%type, 
    O_CRM_ACC_INJ_DET_TPPD out CRM_CLAIM_INT_DETAILS_VIEW.CRM_ACC_INJ_DET_TPPD%type, 
    O_CRM_DRI_LICENSE_NO out CRM_CLAIM_INT_DETAILS_VIEW.CRM_DRI_LICENSE_NO%type, 
    O_CRM_DRI_NAME out CRM_CLAIM_INT_DETAILS_VIEW.CRM_DRI_NAME%type, 
    O_CRM_DRI_RELATION out CRM_CLAIM_INT_DETAILS_VIEW.CRM_DRI_RELATION%type, 
    O_CRM_DRI_VALID_UPTO out CRM_CLAIM_INT_DETAILS_VIEW.CRM_DRI_VALID_UPTO%type, 
    O_CRM_INS_ADDRESS out CRM_CLAIM_INT_DETAILS_VIEW.CRM_INS_ADDRESS%type, 
    O_CRM_INS_CLIENT_ID out CRM_CLAIM_INT_DETAILS_VIEW.CRM_INS_CLIENT_ID%type, 
    O_CRM_INS_CONTACT_NO out CRM_CLAIM_INT_DETAILS_VIEW.CRM_INS_CONTACT_NO%type, 
    O_CRM_INS_MOBILE_NO out CRM_CLAIM_INT_DETAILS_VIEW.CRM_INS_MOBILE_NO%type, 
    O_CRM_INS_NAME out CRM_CLAIM_INT_DETAILS_VIEW.CRM_INS_NAME%type, 
    O_CRM_INS_OFFICE out CRM_CLAIM_INT_DETAILS_VIEW.CRM_INS_OFFICE%type, 
    O_CRM_INS_VEHICLE_NO out CRM_CLAIM_INT_DETAILS_VIEW.CRM_INS_VEHICLE_NO%type, 
    O_CRM_POLICE_STN_NAME out CRM_CLAIM_INT_DETAILS_VIEW.CRM_POLICE_STN_NAME%type, 
    O_CRM_REMARKS out CRM_CLAIM_INT_DETAILS_VIEW.CRM_REMARKS%type, 
    O_CRM_VEH_USED_FOR out CRM_CLAIM_INT_DETAILS_VIEW.CRM_VEH_USED_FOR%type, 
    O_ADDRESSLINE1 out INTRFC_MOTOR_NOTIFICATION_VIEW.ADDRESSLINE1%type, 
    O_ADDRESSLINE2 out INTRFC_MOTOR_NOTIFICATION_VIEW.ADDRESSLINE2%type, 
    O_CITYDISTRICT_NAME out INTRFC_MOTOR_NOTIFICATION_VIEW.CITYDISTRICT_NAME%type, 
    O_CONTACTPERSON_NAME out INTRFC_MOTOR_NOTIFICATION_VIEW.CONTACTPERSON_NAME%type, 
    O_COUNTRY_NAME out INTRFC_MOTOR_NOTIFICATION_VIEW.COUNTRY_NAME%type, 
    O_EMAIL_ID out INTRFC_MOTOR_NOTIFICATION_VIEW.EMAIL_ID%type, 
    O_LANDMARK out INTRFC_MOTOR_NOTIFICATION_VIEW.LANDMARK%type, 
    O_MOBILE_NUMBER out INTRFC_MOTOR_NOTIFICATION_VIEW.MOBILE_NUMBER%type, 
    O_NATUREOFLOSS_DESCRIPTION out INTRFC_MOTOR_NOTIFICATION_VIEW.NATUREOFLOSS_DESCRIPTION%type, 
    O_PINCODE out INTRFC_MOTOR_NOTIFICATION_VIEW.PINCODE%type, 
    O_POLICY_NUM out INTRFC_MOTOR_NOTIFICATION_VIEW.POLICY_NUM%type, 
    O_RELATION_WITH_CUSTOMER out INTRFC_MOTOR_NOTIFICATION_VIEW.RELATION_WITH_CUSTOMER%type, 
    O_REPAIRER_NAME out INTRFC_MOTOR_NOTIFICATION_VIEW.REPAIRER_NAME%type, 
    O_STATE_NAME out INTRFC_MOTOR_NOTIFICATION_VIEW.STATE_NAME%type, 
    O_TEL_NUMBER out INTRFC_MOTOR_NOTIFICATION_VIEW.TEL_NUMBER%type, 
    O_VILLAGE_NAME out INTRFC_MOTOR_NOTIFICATION_VIEW.VILLAGE_NAME%type, 
    O_MAKE out INTRFC_MOTOR_RISK_VIEW.MAKE%type, 
    O_MODEL out INTRFC_MOTOR_RISK_VIEW.MODEL%type, 
    O_AGENT_NAME out INTRFC_POLICY_VIEW.AGENT_NAME%type, 
    O_BRANCH_OFFICE_DESC out INTRFC_POLICY_VIEW.BRANCH_OFFICE_DESC%type, 
    O_MANUAL_COVERNOTE_NO out INTRFC_POLICY_VIEW.MANUAL_COVERNOTE_NO%type, 
    O_RISK_END_DATE out INTRFC_POLICY_VIEW.RISK_END_DATE%type, 
    O_RISK_START_DATE out INTRFC_POLICY_VIEW.RISK_START_DATE%type, 
    O_CHASIS_NO out MO_CLAIM_MASTER.CHASIS_NO%type, 
    O_DATE_OF_NOTIFICATION out MO_CLAIM_MASTER.DATE_OF_NOTIFICATION%type, 
    O_ENGINE_NO out MO_CLAIM_MASTER.ENGINE_NO%type, 
    O_NOTF_FIR_DATE out MO_CLAIM_MASTER.NOTF_FIR_DATE%type, 
    O_NOTIF_ADDRES_POLICE_STATN out MO_CLAIM_MASTER.NOTIF_ADDRES_POLICE_STATN%type, 
    O_NOTIF_CP_EMAIL out MO_CLAIM_MASTER.NOTIF_CP_EMAIL%type, 
    O_NOTIF_DRIVER_OTHER_INFO out MO_CLAIM_MASTER.NOTIF_DRIVER_OTHER_INFO%type, 
    O_NOTIF_LOSS_LOC_TYPE out MO_CLAIM_MASTER.NOTIF_LOSS_LOC_TYPE%type, 
    O_NOTIF_OTHER_REMARKS out MO_CLAIM_MASTER.NOTIF_OTHER_REMARKS%type, 
    O_NOTIF_PLACE_PARKING out MO_CLAIM_MASTER.NOTIF_PLACE_PARKING%type, 
    O_NOTIF_SURVEY_TO_DONE out MO_CLAIM_MASTER.NOTIF_SURVEY_TO_DONE%type, 
    O_NOTIF_SVC_PROV_CONTACT_NUM out MO_CLAIM_MASTER.NOTIF_SVC_PROV_CONTACT_NUM%type, 
    O_NOTIF_SVC_PROV_INFORMED out MO_CLAIM_MASTER.NOTIF_SVC_PROV_INFORMED%type, 
    O_NOTIF_SVC_PROV_NAME out MO_CLAIM_MASTER.NOTIF_SVC_PROV_NAME%type, 
    O_NOTIF_TOYOTA_POLICY_NO out MO_CLAIM_MASTER.NOTIF_TOYOTA_POLICY_NO%type, 
    O_PRODUCT_CODE out MO_CLAIM_MASTER.PRODUCT_CODE%type, 
    O_STATUS out MO_CLAIM_MASTER.STATUS%type 


     ) 
    AS 
     reference_num_var VARCHAR2(50); 
     claim_no_var  NUMBER; 
     crm_sl_no_var  NUMBER; 
     CURSOR c1 
     IS 
     SELECT NV.claim_no, 
      NV.reference_num, 
      NV.ADDRESSLINE1, 
      NV.ADDRESSLINE2, 
      NV.CITYDISTRICT_NAME, 
      NV.CONTACTPERSON_NAME, 
      NV.COUNTRY_NAME, 
      NV.EMAIL_ID, 
      NV.LANDMARK, 
      NV.MOBILE_NUMBER, 
      NV.NATUREOFLOSS_DESCRIPTION, 
      NV.PINCODE, 
      NV.POLICY_NUM, 
      NV.RELATION_WITH_CUSTOMER, 
      NV.REPAIRER_NAME, 
      NV.STATE_NAME, 
      NV.TEL_NUMBER, 
      NV.VILLAGE_NAME 
     INTO claim_no_var, 
      reference_num_var, 
      O_ADDRESSLINE1, 
      O_ADDRESSLINE2, 
      O_CITYDISTRICT_NAME, 
      O_CONTACTPERSON_NAME, 
      O_COUNTRY_NAME, 
      O_EMAIL_ID, 
      O_LANDMARK, 
      O_MOBILE_NUMBER, 
      O_NATUREOFLOSS_DESCRIPTION, 
      O_PINCODE, 
      O_POLICY_NUM, 
      O_RELATION_WITH_CUSTOMER, 
      O_REPAIRER_NAME, 
      O_STATE_NAME, 
      O_TEL_NUMBER, 
      O_VILLAGE_NAME 
     FROM INTRFC_MOTOR_NOTIFICATION_VIEW NV 
      --WHERE NV.claim_no=para_claim_no; 
     WHERE NV.POLICY_NUM=para_claim_no ; 
     t1 c1%rowtype; 
     CURSOR c2 
     IS 
     SELECT PV.AGENT_NAME, 
      PV.BRANCH_OFFICE_DESC, 
      PV.MANUAL_COVERNOTE_NO, 
      PV.RISK_END_DATE, 
      PV.RISK_START_DATE 
      INTO 
      O_AGENT_NAME, 
    O_BRANCH_OFFICE_DESC, 
    O_MANUAL_COVERNOTE_NO, 
    O_RISK_END_DATE, 
    O_RISK_START_DATE 

     FROM INTRFC_POLICY_VIEW PV 
     WHERE PV.NUM_REFERENCE_NUMBER=reference_num_var; 
     t2 c2%rowtype; 
     CURSOR c3 
     IS 
     SELECT RV.MAKE, 
      RV.MODEL 
      INTO 
      O_MAKE, 
    O_MODEL 
     FROM INTRFC_MOTOR_RISK_VIEW RV 
     WHERE RV.reference_num=reference_num_var; 
     t3 c3%rowtype; 
     CURSOR c4 
     IS 
     SELECT CM.notif_crm_sl_no, 
      CM.CHASIS_NO, 
      CM.DATE_OF_NOTIFICATION, 
      CM.ENGINE_NO, 
      CM.NOTF_FIR_DATE, 
      CM.NOTIF_ADDRES_POLICE_STATN, 
      CM.NOTIF_CP_EMAIL, 
      CM.NOTIF_DRIVER_OTHER_INFO, 
      CM.NOTIF_LOSS_LOC_TYPE, 
      CM.NOTIF_OTHER_REMARKS, 
      CM.NOTIF_PLACE_PARKING, 
      CM.NOTIF_SURVEY_TO_DONE, 
      CM.NOTIF_SVC_PROV_CONTACT_NUM, 
      CM.NOTIF_SVC_PROV_INFORMED, 
      CM.NOTIF_SVC_PROV_NAME, 
      CM.NOTIF_TOYOTA_POLICY_NO, 
      CM.PRODUCT_CODE, 
      CM.STATUS 
      INTO 
      crm_sl_no_var, 
      O_CHASIS_NO, 
    O_DATE_OF_NOTIFICATION, 
    O_ENGINE_NO, 
    O_NOTF_FIR_DATE, 
    O_NOTIF_ADDRES_POLICE_STATN, 
    O_NOTIF_CP_EMAIL, 
    O_NOTIF_DRIVER_OTHER_INFO, 
    O_NOTIF_LOSS_LOC_TYPE, 
    O_NOTIF_OTHER_REMARKS, 
    O_NOTIF_PLACE_PARKING, 
    O_NOTIF_SURVEY_TO_DONE, 
    O_NOTIF_SVC_PROV_CONTACT_NUM, 
    O_NOTIF_SVC_PROV_INFORMED, 
    O_NOTIF_SVC_PROV_NAME, 
    O_NOTIF_TOYOTA_POLICY_NO, 
    O_PRODUCT_CODE, 
    O_STATUS 


     FROM MO_CLAIM_MASTER CM 
     WHERE CM.claim_no = claim_no_var; 
     t4 c4%rowtype; 
     CURSOR c5 
     IS 
     SELECT CRM.CRM_ACC_CAL_GARAGE, 
      CRM.CRM_ACC_DAM_COMP, 
      CRM.CRM_ACC_DATE_TIME, 
      CRM.CRM_ACC_DESC, 
      CRM.CRM_ACC_FIR, 
      CRM.CRM_ACC_INJ_DET_TPPD, 
      CRM.CRM_DRI_LICENSE_NO, 
      CRM.CRM_DRI_NAME, 
      CRM.CRM_DRI_RELATION, 
      CRM.CRM_DRI_VALID_UPTO, 
      CRM.CRM_INS_ADDRESS, 
      CRM.CRM_INS_CLIENT_ID, 
      CRM.CRM_INS_CONTACT_NO, 
      CRM.CRM_INS_MOBILE_NO, 
      CRM.CRM_INS_NAME, 
      CRM.CRM_INS_OFFICE, 
      CRM.CRM_INS_VEHICLE_NO, 
      CRM.CRM_POLICE_STN_NAME, 
      CRM.CRM_REMARKS, 
      CRM.CRM_VEH_USED_FOR 
      INTO 
      O_CRM_ACC_CAL_GARAGE, 
    O_CRM_ACC_DAM_COMP, 
    O_CRM_ACC_DATE_TIME, 
    O_CRM_ACC_DESC, 
    O_CRM_ACC_FIR, 
    O_CRM_ACC_INJ_DET_TPPD, 
    O_CRM_DRI_LICENSE_NO, 
    O_CRM_DRI_NAME, 
    O_CRM_DRI_RELATION, 
    O_CRM_DRI_VALID_UPTO, 
    O_CRM_INS_ADDRESS, 
    O_CRM_INS_CLIENT_ID, 
    O_CRM_INS_CONTACT_NO, 
    O_CRM_INS_MOBILE_NO, 
    O_CRM_INS_NAME, 
    O_CRM_INS_OFFICE, 
    O_CRM_INS_VEHICLE_NO, 
    O_CRM_POLICE_STN_NAME, 
    O_CRM_REMARKS, 
    O_CRM_VEH_USED_FOR 
     FROM CRM_CLAIM_INT_DETAILS_VIEW CRM 
     WHERE crm.crm_slno=crm_sl_no_var; 
     t5 c5%rowtype; 
    BEGIN 
    OPEN c1; 
     FETCH c1 INTO t1; 
     CLOSE c1; 
     reference_num_var := t1.reference_num; 
     claim_no_var  := t1.claim_no; 
     OPEN c2; 
     FETCH c2 INTO t2; 
     CLOSE c2; 
     OPEN c3; 
     FETCH c3 INTO t3; 
     CLOSE c3; 
     OPEN c4; 
     FETCH c4 INTO t4; 
     CLOSE c4; 
     crm_sl_no_var :=T4.notif_crm_sl_no; 
     OPEN c5; 
     FETCH c5 INTO t5; 
     CLOSE c5; 
    END NOTIFICATIN_REPORT_TEST; 

回答

3

您可以使用自定義數據類型和流水線功能。 您對「記錄」模板創建類型:

CREATE OR REPLACE 
TYPE O_MY_OBJECT AS OBJECT (
    MY_DATE      DATE 
, MY_NUMBER      NUMBER 
, MY_VARCHAR     VARCHAR2(20) 
); 

然後你的記錄模板的表創建類型:

CREATE OR REPLACE 
TYPE T_MY_OBJECT AS TABLE OF O_MY_OBJECT; 

,然後創建一個返回你的表對象的流水線功能:

FUNCTION MY_FUNCTION(V_MY_PARAM IN VARCHAR2) 
    RETURN T_MY_OBJECT 
    PIPELINED 
AS 
V_MY_OBJ_VAR O_MY_OBJECT := O_MY_OBJECT(null, null, null); 
BEGIN 
     SELECT 
      SYSDATE 
      , 10 
      , 'HELLO WORLD! -> ' || V_MY_PARAM 
     INTO 
      V_MY_OBJ_VAR.MY_DATE 
     , V_MY_OBJ_VAR.MY_NUMBER 
     , V_MY_OBJ_VAR.MY_VARCHAR 
     FROM 
      DUAL; 

     PIPE ROW(V_MY_OBJ_VAR); 

    RETURN; 
END MY_FUNCTION; 

你的情況,你會每次你需要從每個五個光標的循環時間管一排。 一旦你創建了這樣的功能,你可以從它記錄了表查詢:

SELECT * FROM TABLE(MY_FUNCTION('SOME ARGUMENT VALUE, IF NEEDED')); 
+0

嗨安德烈感謝你的答案,但我是新來的管道函數的概念。我試着用你的示例代碼。但我沒有達到結果。如果你可以幫我用兩張表的代碼,那麼我可以對我的5張表做同樣的事情。 – leelavinodh

+0

首先:您必須在結果表中標識所需的一組列(具有相對類型)(您將在UNION查詢中執行什麼操作)。第二:使用該結構和相應的表格定義對象類型,如我的示例中所示。第三:循環遊標c1,c2,c3等,並將值放入您創建的對象中(另一次,您將在UNION查詢中執行的操作)。在每一個循環週期中,你都將管道(把它放在結果表上)該對象。只有當你完成第一項任務後,你才能通過我的例子。 –

+0

嗨安德烈謝謝你,我得到了我的輸出。但是我仍然不清楚第三步。我必須使用多少個循環。目前我只使用一個循環和一個遊標。也想知道如何發佈我的腳本到這個,這樣你就可以看到我的代碼。 – leelavinodh

相關問題