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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:03:29+00:00 2026-06-15T14:03:29+00:00

I have the following pl/sql block: BEGIN FOR I IN 1 .. 5 LOOP

  • 0

I have the following pl/sql block:

BEGIN
  FOR I IN 1 .. 5
  LOOP
    INSERT INTO TEST_TABLE VALUES('&slno',SYSDATE);
  END LOOP;
END;

When I executed the above block it is taking only one input.
But it is supposed to take 5 input in total.
What is missing in my code? Can any one help me please?

  • 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-15T14:03:29+00:00Added an answer on June 15, 2026 at 2:03 pm

    It is a substitution variable – an sql*plus feature – and it doesn’t work this way. You have to call undefine &slno or accept slno ... to make it take another input, but these are also sqlplus, not pl/sql commands, so you won’t be able to invoke them in a loop,

    Probably the only thing you can do here is

    INSERT INTO TEST_TABLE VALUES('&slno1',SYSDATE);
    INSERT INTO TEST_TABLE VALUES('&slno2',SYSDATE);
    INSERT INTO TEST_TABLE VALUES('&slno3',SYSDATE);
    INSERT INTO TEST_TABLE VALUES('&slno4',SYSDATE);
    INSERT INTO TEST_TABLE VALUES('&slno5',SYSDATE);
    

    update: Fortunately, you can work this around by generaing a list of separate sequential statements accepting independent inputs:

    22:38:59 @> conn system/sys@oars_sandbox
    Connected.
    22:39:01 SYSTEM@oars_sandbox> @s:\test
    Enter value for var1: a
    Enter value for var2: b
    Enter value for var3: c
    22:39:06 SYSTEM@oars_sandbox> commit;
    22:39:11 SYSTEM@oars_sandbox> select * from test_table;
    
    COL1       COL2
    ---------- -------------------
    a          07.12.2012 22:39:10
    b          07.12.2012 22:39:11
    c          07.12.2012 22:39:11
    22:39:17 SYSTEM@oars_sandbox> get s:\test
      1  set echo off
      2  set define off
      3  set termout off
      4  set feedback off
      5  set timing off
      6  spool s:\123.sql
      7  begin
      8    for i in 1 .. 3 loop
      9      dbms_output.put_line('insert into test_table values(''&var'||i||''', sysdate);');
     10    end loop;
     11  end;
     12  /
     13  spool off
     14  set define "&"
     15  set termout on
     16* @s:\123.sql
    22:39:24  17  .
    22:39:58 SYSTEM@oars_sandbox> get s:\123.sql
      1  insert into test_table values('&var1', sysdate);
      2  insert into test_table values('&var2', sysdate);
      3* insert into test_table values('&var3', sysdate);
    22:40:04 SYSTEM@oars_sandbox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have the following SQL block (in SQL SERVER 2008 R2): BEGIN BEGIN
I have the following PL/SQL block that creates a procedure to insert a new
I have the following SQL Server stored procedure : BEGIN TRAN CREATE TABLE #TempTable
we have created following anonymous block........... DECLARE sql_str long(32000); where_str long(32000); counter NUMBER(3):=0; BEGIN
I currently have the following block of SQL 2005 code. What I need to
I have following SQL statementL: select DATE(bla), count(*) from tableA group by DATE(bla) UNION
I have following SQL query SELECT TOP 10000 AVG(DailyNodeAvailability.Availability) AS AVERAGE_of_Availability FROM Nodes INNER
Hi I have following sql statement that gives me the the first_name and total
I have the following SQL Server query: SELECT area FROM places WHERE REPLACE(area,'-',' ')
I have the following SQL snippet within a select statement: CASE WHEN wot.id LIKE

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.