Solved

PL/SQL code - ORA-01795: maximum number of expressions in a list is 1000

Posted on 2008-10-06
2
1,878 Views
Last Modified: 2013-12-07
When this query runs, it sometimes was fine, but it sometimes produced this error.  Please advise.
BEGIN

  SELECT

ORA-01795: maximum number of expressions in a list is 1000
ORA-06512: at line 13
**************************************************************************
DECLARE
  v_cnt NUMBER;
  v_ban_list VARCHAR2(30000) := ' ';
BEGIN
  SELECT COUNT(*) INTO v_cnt FROM clm_actual_usage_${INST};

  -- insert 500 rows at a time
  FOR r IN (SELECT ban, ROWNUM AS rownum_id FROM clm_actual_usage_${INST} ORDER BY ban) LOOP
    v_ban_list := v_ban_list || r.ban || ',';
    IF MOD(r.rownum_id, 500) = 0 OR r.rownum_id = v_cnt THEN
      EXECUTE IMMEDIATE '
      INSERT /*+ APPEND */
        INTO tmp_clm_all_${INST}
             (ban, bill_cycle, ar_usage_threshold, customer_type, num_of_product, deposit_ind,
              credit_class,clm_skip_ind, ban_status,start_srvc_dt, billing_type, bc_carrier_id,
              bc_carrier_acct_id, bl_spcl_ban_code, act_usage, clm_typ_cd)
      SELECT /*+ PARALLEL(b, 20) */
             b.ban, b.bill_cycle, b.ar_usage_threshold, b.customer_type,
             NVL(b.num_of_product, 1) AS num_of_product,
             CASE WHEN (b.deposit_ind=''R'' AND ''${CINST}''=''AMT'') OR
                       (b.deposit_ind=''N'' AND ''${CINST}''=''PCT'') OR
                       (b.deposit_ind=''Z'' AND ''${CINST}''=''SWT'') OR
                       (b.deposit_ind=''R'' AND ''${CINST}''=''BLS'') THEN ''N'' ELSE b.deposit_ind END AS deposit_ind,
             b.credit_class, b.clm_skip_ind, b.ban_status, b.start_service_date,
             b.billing_type, b.bc_carrier_id, b.bc_carrier_acct_id, b.bl_spcl_ban_code, NULL AS act_usage,
             DECODE(ar_usage_threshold, NULL, ''G'', ''R'') AS clm_typ_cd
        FROM billing_account@${DB_NAME} b
       WHERE b.ban IN (' || SUBSTR(v_ban_list, 1, LENGTH(v_ban_list) - 1) || ')
      ';
      COMMIT;
      v_ban_list := ' ';
    END IF;
  END LOOP;
END;
/
0
Comment
Question by:scpig
2 Comments
 
LVL 34

Accepted Solution

by:
johnsone earned 250 total points
Comment Utility
The v_ban_list that is being pulled contains more than 1,000 items.  There is a restriction in Oracle that and in list can only contain 1,000 items.

One way round this is to create a global temporary table and load the individual items of the list into that table and then instead of using an in list, use a sub query.
0
 

Author Closing Comment

by:scpig
Comment Utility
yes this works.
and another way to work is to change 500 to 250, which works fine too.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now