请建议我为什么不执行程序:下面给出错误代码

时间:2015-02-11 09:41:10

标签: plsql oracle10g oracle-sqldeveloper

这里我试图创建.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.

1 个答案:

答案 0 :(得分:2)

它与ORA-01403: no data found发生错误,因为您在代码中执行隐式游标(即。select ... into ...而不是cursor cur is select ...),并且如果没有返回任何行,你得到那个错误。所以你必须传入一个不存在的partner_id,导致选择失败。

通常,在使用隐式游标时,应确保处理两个异常条件:找不到数据和行太多。 (在某些情况下,您不需要为过多的行异常而烦恼 - 例如,如果您在主键上进行选择,那么您将永远不会获得多行返回。)