2015-02-11 31 views
-5

在這裏,我想創建.csv文件顯示,從視圖中的兩個字段的數據,請其需要充分如何創建CSV文件請建議我爲什麼不執行程序:下面給出的代碼錯誤

CREATE OR replace PROCEDURE "SP_APPLICANT_AREA_COUNT_REPORT" (
p_partner_id  NUMBER := 999, 
p_user_session_id VARCHAR2 := NULL, 
p_file_path  IN OUT VARCHAR2) 
AS 
    -- NOCOPY 
    --v_USERID NUMBER :=P_USER_ID; 
    --v_TABLE_NAME VARCHAR2(200):=P_TABLE_NAME; 
    --v_PARTNER_ID NUMBER:=P_PARTNER_ID;  
    v_file    utl_file.file_type; 
    cur_field   SYS_REFCURSOR; 
    v_fields   VARCHAR2(32767) := NULL; 
    v_field   VARCHAR2(32767); 
    v_count   NUMBER := 0; 
    v_curfields  VARCHAR2(32767); 
    v_curfilefields VARCHAR2(32767); 
    v_tempfields  VARCHAR2(32767); 
    v_tempfieldsvalues VARCHAR2(32767); 
    v_counter   NUMBER := 1; 
    v_str    VARCHAR2(32767); 
    v_strheader  VARCHAR2(32767); 
    v_curcounter  NUMBER := 1; 
    v_filecount  NUMBER := 1; 
    v_name    VARCHAR2(500) := 'clob2file_buffered1.csv'; 
    c_maxline CONSTANT PLS_INTEGER := 32767; 
    v_eligible_number NUMBER := -999; 
    v_count1   NUMBER := 0; 
    cur_rec   SYS_REFCURSOR; 
    v_file_max_limit NUMBER := 25001; 
    v_search_criteria1 VARCHAR2(4000) := NULL; 
    v_search_criteria2 VARCHAR2(4000) := NULL; 
    v_csvfilename  VARCHAR2(4000); 
    v_ac_name   VARCHAR2(30) := 'bid_reason'; 
    v_rp_name   VARCHAR2(30) := 'Reason of Bid'; 
    v_str_l   VARCHAR2(200) := ''; 
    v_area_description VARCHAR2(500) := NULL; 
    v_applicant_count NUMBER := 0; 
BEGIN 
    IF (p_user_session_id IS NOT NULL) THEN 
     SELECT 'ApplicantCountReport' 
      ||'_' 
      ||p_user_session_id 
      ||'_' 
      ||To_char(SYSDATE, 'ddmmyyhhmissss') 
     INTO v_csvfilename 
     FROM dual; 
    ELSE 
     SELECT 'ApplicantCountReport' 
      ||To_char(SYSDATE, 'ddmmyyhhmissss') 
     INTO v_csvfilename 
     FROM dual; 
    END IF; 

    SELECT area_description 
    --INTO v_AREA_DESCRIPTION 
    FROM applicant_area_count_view 
    WHERE partner_id = p_partner_id; 

    SELECT applicant_count 
    INTO v_applicant_count 
    FROM applicant_area_count_view 
    WHERE partner_id = p_partner_id; 

    /* select AREA_DESCRIPTION,APPLICANT_COUNT 
     INTO v_AREA_DESCRIPTION,v_APPLICANT_COUNT 
     from APPLICANT_AREA_COUNT_VIEW 
     where PARTNER_ID=P_PARTNER_ID; 

    */ 
    BEGIN 
     /* 
     v_name:=substr(v_name,0,length(v_name)-6)||'_'||TO_CHAR(v_fileCount)||'.csv'; 
     */ 
     v_name := v_csvfilename 
        ||'_' 
        ||To_char(SYSDATE, 'YYYYMMDD') 
        ||'.csv'; 

     v_file := utl_file.Fopen(location => 'CBLDOC_DIR', filename => v_name, 
        open_mode => 'w', 
          max_linesize => c_maxline); 

     utl_file.Put_line(v_file, v_name); 

     p_file_path := p_file_path 
         ||v_name 
         ||','; 
    EXCEPTION 
     WHEN OTHERS THEN 
      utl_file.Fclose(v_file); 
    END; 

    dbms_output.Put_line(v_name); 
EXCEPTION 
    WHEN OTHERS THEN 
      RAISE; 
--raise_application_error (-20002,'An error has occurred.'); 
--raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM); 
END; 


ERROR: ERROR:- ORA-01403: no data found 
ORA-06512: at "CBLLIVE21092011_DEV.SP_APPLICANT_AREA_COUNT_REPORT", line 108 
ORA-06512: at line 10 
Process exited. 
+0

因爲你的select語句之一沒有找到數據?當你正在調試時,你正在捕捉「其他人」,它隱藏了發生錯誤的實際行,這是非常無益的。如果這是當前代碼,推測它必須是來自'APPLICANT_AREA_COUNT_VIEW'的查詢;註釋掉的「進入」條款表明它不是。 – 2015-02-11 09:50:12

+0

_ORA-01403:找不到數據ORA-06512:在「CBLLIVE21092011_DEV.SP_APPLICANT_AREA_COUNT_REPORT」中,第108行解釋它 – Sathya 2015-02-11 09:53:19

回答

2

這是ORA-01403: no data found錯誤,因爲您在代碼中執行隱式遊標(即select ... into ...而不是cursor cur is select ...),並且如果沒有行返回,則會出現該錯誤。所以你必須傳遞一個不存在的partner_id,導致選擇失敗。

通常,使用隱式遊標時,應確保處理兩個異常情況:未發現數據和行數過多。 (在某些情況下,您不必擔心太多的行異常 - 例如,如果您選擇的是主鍵,那麼您永遠不會得到多於一行的返回結果。)

+0

謝謝大家,問題已修復,再次非常感謝您的支持。 – 2015-02-12 13:43:34

相關問題