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 9332361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T06:33:00+00:00 2026-06-19T06:33:00+00:00

Currently I have in my pl/sql code following statements: — vList looks like ‘1,2,3,4’

  • 0

Currently I have in my pl/sql code following statements:

-- vList looks like '1,2,3,4'     
vStatement := 'SELECT NAME FROM T_USER WHERE ID IN ( ' || vList || ' ) '; 
Execute Immediate vStatement BULK COLLECT INTO tNames;

I think that concatenating of query if bad practice, so I want to make this query without using stings. What is the way to rewrite this ?

P.S. maybe people here can point out why concatenation of queries is bad, because i don’t have enough reasons to prove that this style is bad.

  • 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-19T06:33:01+00:00Added an answer on June 19, 2026 at 6:33 am

    my guess is that you took some steps previously to get vList id’s into a delimited string (you don’t say how vList was populated ). Why not keep as one query?

    begin
    ...
    select name
    bulk collect into tNames
    from t_user
    where id in (select id from some_table where ...);
    ...
    

    Context switching when run many times can be painful, but to me the worst part is that you are blindly accepting parameter input to be a list of numbers, when it could be anything really. It could (innocently) be ‘1,2,X’, and you’ll get a runtime error “invalid number”. Or worse, it could be a SQL injection attack. Its bad practice in general (dynamic sql does have its place), but definitely NOT how you’re using it.

    Try something like this:

    create or replace type t_num_tab as table of number;
    
    create or replace procedure test_proc(i_list in t_num_tab) as
      type t_name_tab is table of varchar2(100);
      l_names t_name_tab;
    begin
      -- get names
      select name
      bulk collect into l_names
      from user_table
      where id in (select * from table(i_list));
    
      -- do something with l_names
      dbms_output.put_line('Name count: ' || l_names.count);
    
    end;
    

    You can create an object type if you need something more complicated than a list of numbers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have the following block of SQL 2005 code. What I need to
I have SQL statements generated like the following. Note that the parameters @p1 and
I currently have the following SQL query that lists all the names of all
I currently have a filesystem path I would like to index into a SQL
I have the following SQL design issue. The code below might look a little
I currently have this line of code, which works perfectly: $data2 = mysql_query(SELECT *
I have the following SQl statement: SELECT id + 100000000000000000 AS id, a.external_code +
I have the following sql statement: SELECT COUNT(table2.programName), table2.programName FROM table1 LEFT JOIN table2
I currently have this sql statement that I wrote and it works but it's
I currently have two SQL commands. One retrieves a list of unique IDs from

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.