Solved

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

Posted on 2008-10-06
2
1,884 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
ID: 22651863
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
ID: 31503491
yes this works.
and another way to work is to change 500 to 250, which works fine too.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

911 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

21 Experts available now in Live!

Get 1:1 Help Now