Oracle游标不返回完整的结果集

时间:2016-01-27 18:38:19

标签: java oracle stored-procedures cursor

这篇文章是关于生成动态SQL的问题的延续。 for loop inside a cursor oracle

下面是我正在执行的PL / SQL,它通过循环创建如上文帖子中提到的TYPE来生成动态sql。

PROCEDURE p_XXX_XX(
    p_id_i IN VARCHAR2,
    p_error_code_o OUT VARCHAR2,
    p_error_message_o OUT VARCHAR2,
    pcur_XXX OUT SYS_REFCURSOR )
  AS
  l_array siebel.intl_crm.t_array;
  strSelect_statement  VARCHAR2(20000);
  BEGIN
  l_array := f_Split_String(p_company_id_i);

    strSelect_statement := 
    'SELECT contact.row_id AS contact_id, 
        contact.fst_name AS contact_first_name, 
        contact.last_name AS contact_last_name,
        contact.cell_ph_num AS cell_phone,
        contact.email_addr AS email_address,
        party.party_id AS company_id,
        addr.addr AS address_line_1,
        addr.addr_line_2 AS address_line_2,
        addr.addr_line_3 AS address_line_3,
        addr.city,
        addr.state AS state_province,
        addr.zipcode,
        addr.country,
        NULL AS raw_most_recent_activity_dt,
      contact.work_ph_num AS work_phone,
      contact.alt_email_addr AS alternate_email,
      contact.x_preferred_phone AS preferred_phone,
      contact.x_preferred_email AS preferred_email,
      contact.suppress_email_flg AS email_flag,
      contact.fax_ph_num AS fax_phone, 
      NULL AS most_recent_activity_dt, 
      NULL AS mra_company_id, 
      NULL AS mra_company_name,
      NULL AS accnt_val_cd
      FROM s_party_per party 
      JOIN s_contact contact 
      ON party.person_id = contact.row_id 
      LEFT JOIN siebel.s_addr_per addr
      ON contact.pr_per_addr_id = addr.row_id
      WHERE party.reference_type_cd ='''||'Current Employee' 
      ||'''AND UPPER(TRIM(contact.cust_stat_cd)) ='''||'CURRENT' 
      ||'''AND party.party_id IN (';
      FOR i IN l_array.FIRST .. l_array.LAST LOOP
      strSelect_statement := strSelect_statement ||
                             '''' || l_array(i) || ''',';
      END LOOP;
      -- Get rid of the unwanted trailing comma
      strSelect_statement := SUBSTR(strSelect_statement, 1,
                                  LENGTH(strSelect_statement)-1);     
      -- Add a right parentheses to close the IN list
      strSelect_statement := strSelect_statement || ')';
      dbms_output.put_line('query: '||strSelect_statement);
      -- Open the cursor
      OPEN pcur_company_contacts_new FOR strSelect_statement;
    p_error_code_o     := SQLCODE;
    p_error_message_o  := SQLERRM;
  END p_company_contact_new;

下面是循环遍历数组后生成的SQl

    SELECT contact.row_id AS contact_id, 
            contact.fst_name AS contact_first_name, 
            contact.last_name AS contact_last_name,
            contact.cell_ph_num AS cell_phone,
            contact.email_addr AS email_address,
            party.party_id AS company_id,
            addr.addr AS address_line_1,
            addr.addr_line_2 AS address_line_2,
            addr.addr_line_3 AS address_line_3,
            addr.city,
            addr.state AS state_province,
            addr.zipcode,
            addr.country,
            NULL AS raw_most_recent_activity_dt,
          contact.work_ph_num AS work_phone,
          contact.alt_email_addr AS alternate_email,
          contact.x_preferred_phone AS preferred_phone,
          contact.x_preferred_email AS preferred_email,
          contact.suppress_email_flg AS email_flag,
          contact.fax_ph_num AS fax_phone, 
          NULL AS most_recent_activity_dt, 
          NULL AS mra_company_id, 
          NULL AS mra_company_name,
          NULL AS accnt_val_cd
          FROM s_party_per party 
          JOIN s_contact contact 
          ON party.person_id = contact.row_id 
          LEFT JOIN siebel.s_addr_per addr
          ON contact.pr_per_addr_id = addr.row_id
          WHERE party.reference_type_cd ='Current Employee'AND UPPER(TRIM(contact.cust_stat_cd)) ='CURRENT'AND party.party_id IN ('3-9TTCJ2','1-19G1TZ','1-B3-4924','1-B1-2288','1-160JF','1-1QFF2L',
'1-AZ-1282','1-B5-2052','1-UJHQ9','3-C75CSW','3-C7GDYR',);

当我在编辑器中运行生成的SQL时,它会获取所有传递的id的结果集。但是当我运行PL / SQL块时,它只返回结果集的一部分而不是完整集。我从java调用这个过程,当我单独测试这些id时,我看到数据库中的数据。我猜这个问题是返回CURSOR。有没有人面临类似的问题?

提前致谢!

0 个答案:

没有答案