Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8075785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:06:20+00:00 2026-06-05T15:06:20+00:00

This works when I have only one state code as a parameter. How can

  • 0

This works when I have only one state code as a parameter.

How can I get code to work when I have more than one state_code in parm_list?

Requirements:

(1)I don’t want to hard code the state codes in my cursor definition

(2) I do want to allow for more than one state code in my where clause

For example: I want to run this code for parm_list = (‘NY’,’NJ’,’NC’).
I’m encountering difficulties in reconciling single quotes in parm_list with the single quotes in the ‘where state_code in ‘ query.

set serveroutput on;

DECLARE
parm_list varchar2(40);

cursor get_state_codes(in_state_codes varchar2)
is
select state_name, state_code from states
where state_code in (in_state_codes);

BEGIN
 parm_list := 'NY';
 for get_record in get_state_codes(parm_list) loop
  dbms_output.put_line(get_record.state_name || get_record.state_code);
 end loop;
END;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:06:22+00:00Added an answer on June 5, 2026 at 3:06 pm

    Using dynamic SQL is the simplest approach from a coding standpoint. The problem with dynamic SQL, though, is that you have to hard parse every distinct version of the query which not only has the potential of taxing your CPU but has the potential to flood your shared pool with lots of non-sharable SQL statements, pushing out statements you’d like to cache, causing more hard parses and shared pool fragmentation errors. If you’re running this once a day, that’s probably not a major concern. If hundreds of people are executing it thousands of times a day, that is likely a major concern.

    An example of the dynamic SQL approach

    SQL> ed
    Wrote file afiedt.buf
    
      1  declare
      2    l_deptnos  varchar2(100) := '10,20';
      3    l_rc       sys_refcursor;
      4    l_dept_rec dept%rowtype;
      5  begin
      6    open l_rc for 'select * from dept where deptno in (' || l_deptnos || ')';
      7    loop
      8      fetch l_rc into l_dept_rec;
      9      exit when l_rc%notfound;
     10      dbms_output.put_line( l_dept_rec.dname );
     11    end loop;
     12    close l_rc;
     13* end;
    SQL> /
    ACCOUNTING
    RESEARCH
    
    PL/SQL procedure successfully completed.
    

    Alternately, you can use a collection. This has the advantage of generating a single, sharable cursor so you don’t have to worry about hard parsing or flooding the shared pool. But it probably requires a bit more code. The simplest way to deal with collections

    SQL> ed
    Wrote file afiedt.buf
    
      1  declare
      2    l_deptnos  tbl_deptnos := tbl_deptnos(10,20);
      3  begin
      4    for i in (select *
      5                from dept
      6               where deptno in (select column_value
      7                                  from table(l_deptnos)))
      8    loop
      9      dbms_output.put_line( i.dname );
     10    end loop;
     11* end;
    SQL> /
    ACCOUNTING
    RESEARCH
    
    PL/SQL procedure successfully completed.
    

    If, on the other hand, you really have to start with a comma-separated list of values, then you will have to parse that string into a collection before you can use it. There are various ways to parse a delimited string– my personal favorite is to use regular expressions in a hierarchical query but you could certainly write a procedural approach as well

    SQL> ed
    Wrote file afiedt.buf
    
      1  declare
      2    l_deptnos     tbl_deptnos;
      3    l_deptno_str  varchar2(100) := '10,20';
      4  begin
      5    select regexp_substr(l_deptno_str, '[^,]+', 1, LEVEL)
      6      bulk collect into l_deptnos
      7      from dual
      8   connect by level <= length(replace (l_deptno_str, ',', NULL));
      9    for i in (select *
     10                from dept
     11               where deptno in (select column_value
     12                                  from table(l_deptnos)))
     13    loop
     14      dbms_output.put_line( i.dname );
     15    end loop;
     16* end;
     17  /
    ACCOUNTING
    RESEARCH
    
    PL/SQL procedure successfully completed.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code works perfectly. I only have one question, I want to make it
I have code like this. I click on button and it works only few
I have tried : c(module_name). : but this only works from the shell, and
Note: This problem occurs only on Mac, on Windows works fine. I have a
I have to do something like this in C. It works only if I
Possible Duplicate: Replacing unquoted words only in Python This is what I have right
This works in all other browsers and I have no idea what the problem
I have no idea how this works or if it is even possible but
I have a line in my SQL Stored Procedure that looks like this (works
We currently have a working php mail script, this works fine and as we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.