Why substitution variable &input line don't execute on a loop?

Hi Group,
Why the line where substitution variable is assigned doesn't execute over the loop. only the first time.
SET SERVEROUTPUT ON
DECLARE
     v_flag NUMBER(1):= 0;
     v_counter NUMBER(1):= 0;
BEGIN
     LOOP                     
          v_flag := &input;
          v_counter := v_counter + 1;
          dbms_output.put_line(v_counter);
          EXIT WHEN v_counter = 9;
     END LOOP;
END;
/thanks.

Hi,
user12152340 wrote:
Thanks for your help... so there's no way to interact with the database inside a loop. I was looking a way that PLSQL block asks for different values.No, sorry. PL/SQL can't do any kind of user interaction. That's what front-end tools, like Apex, are for.
You can have loops in SQL*Plus, but it's not pretty. See this thread:
Re: How to give the different values to runtime parameters in a loop?

Similar Messages

  • Mitigating SQL injection when forced to use substitution variables

    The 3rd party software that I use has exactly one way of allowing users to specify runtime parameters: Substitution variables.
    The scripts are executed using SQL*Plus. I'm looking for ways to secure this.
    Please don't say "Don't use substitution variables" - read above, it's the only way this software works.
    My first thought was something like this:
    var myvar varchar2(30)
    exec :myvar := '&user_input';That's no good. What if the user specifies "X'; execute immediate 'drop table sometable" Then we get
    exec :myvar := 'X'; execute immediate 'drop table sometable';Again, no good.
    I thought perhaps something like the following would work:
    exec :myvar := dbms_assert.noop('&user_input');but then again, a malicious user could specify "'); execute immediate 'drop table sometable'; dbms_assert.noop('"
    I'm open to suggestions.
    What can I do to sanitize substitution variables?
    Thank you!
    Edited by: krissco on Jan 30, 2013 3:02 PM

    You could use:
    var myvar varchar2(30)
    exec :myvar := DBMS_ASSERT.ENQUOTE_LITERAL('&user_input');For example:
    SQL> exec :myvar := '&user_input';
    Enter value for user_input: X';execute immediate 'begin dbms_output.put_line(''XXXX'');end;
    XXXX
    PL/SQL procedure successfully completed.
    SQL> exec :myvar := DBMS_ASSERT.ENQUOTE_LITERAL('&user_input');
    Enter value for user_input: X';execute immediate 'begin dbms_output.put_line(''XXXX'');end;
    BEGIN :myvar := DBMS_ASSERT.ENQUOTE_LITERAL('X';execute immediate 'begin dbms_output.put_line(''XXXX'');end;'); END;
    ERROR at line 1:
    ORA-06550: line 1, column 48:
    PLS-00103: Encountered the symbol ";" when expecting one of the following:
    ) , * & = - + < / > at in is mod remainder not rem =>
    <an exponent (**)> <> or != or ~= >= <= <> and or like like2
    like4 likec as between from using || multiset member
    submultiset
    The symbol ")" was substituted for ";" to continue.
    ORA-06550: line 1, column 110:
    PLS-00103: Encountered the symbol ")" when expecting one of the following:
    * & = - + ; < / > at in is mod remainder not rem return
    returning <an exponent (**)> <> or != or ~= >= <= <> and or
    like like2 like4 likec between into
    SQL>SY.
    Edited by: Solomon Yakobson on Jan 30, 2013 8:28 PM

  • Isql*plus 9.2 problem: Substitution variables

    hi, i'm new to using isql*plus.
    i have written the following script to setup my the structure of a database, it works but when i execute it it asks me to:
    Substitution Variables
    Enter values for substitution variables in the script to execute:
    Variable      Value
    d
    I cant work out why, please help.
    here's the script:
    --author: daniel smith
    --student number: 2235592
    --date: 17/02/2005
    --isql plus
    --Application Development and Database (AD&D)
    --Assessment 3
    --drop existing tables
    drop table expense;
    drop table sess;
    drop table assignment;
    drop table task;
    drop table stage;
    drop table project;
    drop table task_type;
    drop table employee;
    drop table grade;
    --create new tables
    create table grade
    grade_no number(6) primary key,
    description varchar2(50),
    rate_per_hour number(5,2)
    create table employee
    employee_no number(6) primary key,
    surname varchar2(50),
    first_name varchar2(50),
    grade_no number(6),
    foreign key (grade_no) references grade(grade_no)
    create table task_type
    task_type_no number(6) primary key,
    description varchar2(50),
    grade_no number(6),
    foreign key (grade_no) references grade(grade_no)
    create table project
    project_no number(6) primary key,
    project_code varchar2(50),
    client varchar2(50),
    description varchar2(50),
    manager number(6),
    foreign key (manager) references employee(employee_no)
    create table stage
    project_no number(6),
    stage_no number(6),
    description varchar2(50),
    Start_date date,
    planned_Duration number(6,1),
    fees_basis varchar2(2),
    primary key (project_no,stage_no),
    foreign key (project_no) references project(project_no),
    constraint fees_basis_ck check(fees_basis IN ('fq','vs','vn','cs','cn'))
    create table task
    project_no number(6),
    stage_no number(6),
    task_no number(6),
    description varchar2(50),
    estimated_hours number(6,2),
    planned_start_date date,
    max_duration number(6,2),
    task_type_no number(6),
    primary key (project_no,stage_no,task_no),
    foreign key (project_no,stage_no) references stage(project_no,stage_no),
    foreign key (task_type_no) references task_type(task_type_no)
    create table Assignment
    project_no number(6),
    stage_no number(6),
    task_no number(6),
    employee_no number(6),
    estimated_hours number(6),
    primary key (project_no,stage_no,task_no,employee_no)
    create Table Sess
    Session_no number(6),
    Session_date date,
    actual_Hours number(6),
    chargeable char(1),
    project_no number(6),
    stage_no number(6),
    task_no number(6),
    employee_no number(6),
    primary key (Session_no),
    Foreign key (project_no, stage_no, task_no, employee_no)
    references Assignment(project_no, stage_no, task_no, employee_no),
    constraint chargeable_sess check(chargeable IN ('y','n'))
    create table expense
    expense_no number(6),
    description varchar2(50),
    quantity number(4),
    unit_cost number(4,2),
    chargeable char(1),
    project_no number(6),
    primary key(expense_no),
    foreign key(project_no) references project(project_no),
    constraint chargeable_exp check(chargeable IN ('y','n'))
    **********************************************************

    << ..
    << --Application Development and Database (AD&D)
    << --
    take the '&' off your script,
    oracle thinks you want to define variable D,
    and obviously you don't want that

  • Alternative to Substitution Variables

    I'm attempting to loop though some logic X number of times based on a user-defined (defined using substitution variable) parameter. Within the loop I need to have user-definable parameter as well. Since substitution variables cannot be used in a loop I'll need an alternative.
    Here an example:
    accept L_num_recs NUMBER PROMPT 'Enter Number of Records (0-9);
    BEGIN
    FOR i in 1..&L_num_recs LOOP
    parameter1 := &m1
    parameter2 := &m2
    END LOOP
    END;
    Because &m1 and &m2 are substitution variables they are bound each time through the loop.
    Any thoughts? Thanks!

    Just assign those subs to local variables and then use the local variables in the loop:
    sql>accept l_num_recs number prompt 'Enter Number of Records (0-9): '
    Enter Number of Records (0-9): 3
    sql>declare
      2    v_text1 number := &m1;
      3    v_text2 number := &m2;
      4  begin
      5    for i in 1..&l_num_recs loop
      6      dbms_output.put_line( v_text1 );
      7      dbms_output.put_line( v_text2 );
      8    end loop;
      9  end;
    10  /
    Enter value for m1: 55
    old   2:   v_text1 number := &m1;
    new   2:   v_text1 number := 55;
    Enter value for m2: 77
    old   3:   v_text2 number := &m2;
    new   3:   v_text2 number := 77;
    old   5:   for i in 1..&l_num_recs loop
    new   5:   for i in 1..        3 loop
    55
    77
    55
    77
    55
    77
    PL/SQL procedure successfully completed.

  • Unable to execute the substitution variable in calc scripts in essbase 11.1

    Unable to execute the substitution variable in calc scripts in essbase 11.1.3
    FIX(&CURRVERSION,COLA)
    Unit=units*Listprice;
    dataexport "file" "," "E:\NEW.TXT";
    ENDFIX
    Error: 1200471 Error parsing formula for FIX STATEMENT (line 1): expression expected before [)]
    This is error it throws when executing the calculation script
    I wonder whether its a problem with substitution variable i want to know wat went wrong inside the fix statement
    I have created substitution variable use maxl
    Installed the essbase in custom manner and standlone mode nt register with the shared services ,
    Is this problem with the custom installation of essbase
    Regards
    shenna

    If you remove the substitution variable and replace it with the actual value (whatever that is), does the code work? That will tell you if the issue is around the substitution variable or not.
    John -- First you race Glenn, then you race me -- and you always win. :)
    Regards,
    Cameron Lackpour

  • Reason: Error in sieve filter: Unknown function/variable found: church around input line 79 [ stop; } require " f^ileinto"; if header ]

    My wife's email has been getting filled with hundereds of emails with this in them this morning. I don't see where anyone else is having this problem today, but I wanted to see if it's on iCloud's end or ours.
    Processing errors occurred during delivery:
    Recipient address: [email protected]
    Reason: Error in sieve filter: Unknown function/variable found: church around input line 79 [ stop; } require " f^ileinto"; if header ]
    Delivery processing continued in spite of these errors.
    Reporting-MTA: dns;ms21034.mac.com (tcp_intranet-daemon)
    Arrival-date: Tue, 13 Mar 2012 07:33:18 +0000 (GMT)

    My Wife and I both have an Ipad and an iPhone, I use an iMac and my wife a MacBook Pro.
    I have this problem with all my devices.
    My wife has NOT got this problem.
    We both use a [email protected] email acount.
    Just compared the settings:
    For "Incoming server" I have p03-imap.mail.me.com
    My Wife has p02-imap.mail.me.com .... and has not got this problem.
    I have setup a new rule for incoming mails (for the meantime):
    move all incoming emails from [email protected] to trash and delete it.
    Works fine for now,......until APPLE deals with the problem.
    Message was edited by: RTONLINE

  • Substitution variables by executing a SQL statement

    If there is a "&text" in a SQL Statement, then SQLDEV automatically interprets this as an "substitution variable" and pops-up a box for entering the values of the variable(s) or takes the value of the "define myvariable myvalue;" statement. How can I turn this feature off? Is there a preference or a SQL-Plus Statement, so that SQLDEV ignores the "&variables"?
    Cause: I have to run some (large) SQL-skripts, which contain some "&text", which should NOT be interpreted as substitution variables.

    SET DEFINE OFF
    SS

  • Substitution Variables just don't work for me

    I have a database that I want to copy data from one version of existing data to another version using substitution variables.<BR><BR>I have a version of (target) data named "Flash Sep Test" that I want to copy to, and a version (source) "HQ1" with the data I want to copy from <BR><BR>My substitution variable at (same) database level is called "Flash1" with value of "Sep"<BR><BR>My calc script code is:<BR><BR>DATACOPY "HQ1" TO "Flash &Flash1 Test";<BR><BR>When I run the calc I get this error:<BR><BR>Invalid Member name "Flash &Flash1 Test" and it won't copy the data over.<BR><BR>Any suggestions on how to get this to work will be much appreciated...HELP!!!???<BR><BR><BR>Sign me,<BR>A very frustrated db admin<b>Text</b>

    Andy and Will,<BR><BR>Thanks for your help!<BR><BR>I figured out to use the variable value with the quotes like this <BR><BR> <b>"Flash Sep Test"</b> <BR><BR>did work when I just placed the variable name <BR><BR> <b>&varFlash</b> <BR><BR>in the calc code without quote marks. Sure wish Essbase's help function explained the use of this (and other code) better than it does. Hope it has improved by ver 7.#.<BR><BR>Thanks again for your assistance!<BR><BR>Alan Hartt<BR>Hewlett Packard

  • Problem with my substitution variable.

    My substitution variables don't prompt properly now. It worked fine before, but I don't know what I did to it. Here is the test code:
    set define on;
    connect sys/&sysPassword @&instanceName as sysdba;
    execute dbms_output.put_line('this is a test');
    When I tried to execute above lines in sqlplus, it didn't prompt anything, but got following result instead:
    SQL> set define on;
    SQL> connect sys/&sysPassword@&instanceName as sysdba;
    Enter value for syspassword: execute dbms_output.put_line('this is a test');
    Enter value for instancename:
    SP2-0306: Invalid option.
    Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}]
    where <logon> ::= <username>[<password>][@<connect_string>] | /
    SQL>
    I remember when I used substitution variables before in sqlplus worksheet, it popup a dialog for input, but it doesn't anymore.
    Any ideas about this issue? Or what setting could affect the behavior? Thanks in advance.

    It would work only if you put these set of statements in a .SQL file and run that file at SQL*Plus prompt:
    SQL> @the_sql_script_created_above.SQL

  • Problem setting the value of a substitution variable in a calc script

    Hi, All.
    I'm trying to update the value of a substitution variable inside an IF statement and I'm having trouble.
    Here's the code:
    *"Jan"(*
    IF  (LoopCounter = 1) &varEntity = "100";
    ENDIF;)
    the error I get back from EAS is:
    Error: 1200336 Error parsing formula for [Jan] (line 54): [(] without [)]

    I know CL knows a lot about HBR, if he's around today... LOL
    As a matter of fact, I just used an HBR (not using Calc Manager till I have to)'s macro functionality to drive fx for different Scenarios in a Planning app. Here's how I call the macro:
              /*     Call the macro mcrFxCoreOutYears for the four fx rate types for ALL 12 months of the year.     */
              FIX(&BudYear)
                   %mcrFxCoreOutYears(Constant)
                   %mcrFxCoreOutYears(Comparable)
                   %mcrFxCoreOutYears(Estimate)
                   %mcrFxCoreOutYears(Actual)
              ENDFIXI pass the Scenarios Constant, Comparable, Estimate, and Actual to the macro mcrFxCoreOutYears. You can apply HBRs against Essbase.
    I believe (I can't remember what exactly -- is it that templates don't accept parameters? That seems hard to believe. Looking at a CM template, that does seem to be the case. Bummer if I'm right.) that Calc Manager BRs have less functionality wrt templates, but I haven't worked with CM for over a year.
    It works really well -- a single place to maintain code and no appreciable performance cost.
    You cannot launch a HBR from a MaxL script but HBRs can be launched from command lines -- this may constrain where you place your automation (it basically has to run off of whatever the EAS server is. You may end up shelling out of MaxL to execute the HBR or even execute scripts across servers -- that does get more complicated.).
    Anyway, if you have any more questions, ask away -- it really is a very powerful component. I will have to look at CM more closely (sooner or later I will lose the HBR vs CM argument and at least need to know if templates support parameters) to see if I'm right on what I wrote above.
    Regards,
    Cameron Lackpour
    P.S. You cannot define an ARRAY in an HBR macro because ARRAY arrayname[value] gets read as a parameter. I ended up declaring the array in the calling HBR.
    P.P.S. I really need to write up the fx approach in a blog post -- it is wicked fast and really easy to use. Too many other posts in the queue already.
    Edited by: CL on Aug 24, 2011 1:48 PM

  • Multiple input lines

    How can I get multiple input lines?
    I'm brand new to java and I have searched the web for a little while to find how I can do this. But I couldn't find a thing.
    Until now I have used JOptionPane to have my inputs, is there another way to get input?

    Better yet try this:
    import java.io.*;
    import java.util.*;
    class Inputline1
         public static void main(String args[]) throws IOException
                JOptionPane.showMessageDialog(null,"Enter in strings, 'stop' to stop","Multiple Input",JOptionPane.INFORMATION_MESSAGE);
                ArrayList str=new ArrayList();
                   String tempInput="";                  
                   String output="";
                    while(!(tempInput.equalsIgnoreCase("stop"))){
                   tempInput=JOptionPane.showInputDialog(null,"String input: ","Multiple Input",JOptionPane.INFORMATION_MESSAGE);
                    if(!(tempInput.equalsIgnoreCase("stop")))
                               str.add(tempInput);
                       for(int x=0;x<str.size();x++){
                           String tempInput=(String)str.get(x);                   
                            output+="/n"+tempInput;
    }What I'm using is called an ArrayList. Simply put...it's an array that you don't say how big it is...it automatically knows by how many elements you add to it. It holds objects, and in your case Strings. When you're getting an object from the array you need to typecast is (that's why i have (String) in front of the str.get(x). Because arraylists only hold objects you need to tell it what kind of object you're getting from it when you're assigning your variable. Useful methods are .add() adds an object to the list and automatically resizes it, .remove() removes and object to the list and automatically resized it, .get() retrieving a copy of the object from the list, and .size() returns the length of the list. Check the API for details on it obviously. Well I hope that helped.

  • Using substitution variable in sql -- Issue

    Hello All
    I am trying to do a sql operation from command prompt of my system and that sql requires substitution variable which i am passing it but when i pass the variable ( there are two) the first one assign as " \c" and second gets both what i am passing.
    I am not sure what exactly happening here, i have done this on AIX but here its not working any ideas?
    System : uname -a
    Linux ## 2.6.18-128.1.1.el5 #1 SMP Mon Jan 26 13:58:24 EST 2009 x86_64 x86_64 x86_64 GNU/Linux

    AIX and Linux are not the same. An output of "\c" may indicate a compatibility issue of your shell script with your current command line interpreter (shell). A \c can be used to suppress a newline with the echo command. Bash understands both formats echo -n and echo \c, but other shells like Ksh don't. Try to run your script under a Bash, which is the default under Linux. If the problem persists you will need to post your script for any further analysis.

  • Error with define substitution variable in SQL

    Hi there,
    I am using PL/SQL developer and trying to define a substitution variable as follows:
    define freq = 'Weekly'
    Then later on, in my SQL statement, I used this variable in WHERE statement as follows:
    WHERE ... (&freq = 'Weekly') and ...
    But I got the "ORA-00904: "WEEKLY": invalid identifier" error.
    Where is the problem?
    Thanks in advance!

    I don't know about PL/SQL developer but in sqlplus you need single quotes around the variable.
    SQL> define freq = 'Weekly'
    SQL> select null from dual
      2  where &freq = 'Weekly';
    old   2: where &freq = 'Weekly'
    new   2: where Weekly = 'Weekly'
    where Weekly = 'Weekly'
    ERROR at line 2:
    ORA-00904: "WEEKLY": invalid identifier
    SQL> edi
    Wrote file afiedt.sql
      1  select null from dual
      2* where '&freq' = 'Weekly'
    SQL> /
    old   2: where '&freq' = 'Weekly'
    new   2: where 'Weekly' = 'Weekly'
    N
    SQL>

  • Substitution Variable in WA error

    Hi there,
    We have moved our server's IP beacuse we promoted developement (server07) to production (server08). Prior to that all reports worked fine. Now we're having some problems with the Substitution Variables, because everytime we select them, to include them in a report, it displays the following error:
    *"Actual_Month is not a valid substitution variable for dimension Period"*
    In fact I've tried to create a new variable with a new name and I get the same error. What intrigues me is that if we use the same variable for Dynamic Time Series let's say Y-T-D(Actual_Month) it works and displays a value.
    Maybe is there something in the connection but still with no clue how to fix it. Any database or setting at the config file to set?
    Thanks!

    I don't know about PL/SQL developer but in sqlplus you need single quotes around the variable.
    SQL> define freq = 'Weekly'
    SQL> select null from dual
      2  where &freq = 'Weekly';
    old   2: where &freq = 'Weekly'
    new   2: where Weekly = 'Weekly'
    where Weekly = 'Weekly'
    ERROR at line 2:
    ORA-00904: "WEEKLY": invalid identifier
    SQL> edi
    Wrote file afiedt.sql
      1  select null from dual
      2* where '&freq' = 'Weekly'
    SQL> /
    old   2: where '&freq' = 'Weekly'
    new   2: where 'Weekly' = 'Weekly'
    N
    SQL>

  • Peculiar problem with Essbase (Calc Script) - substitution variable / UDAs

    This is odd but I have a script like :
    VAR iloop=1,break=0;
    FIX(<required POV>)
    Loop (20,break)
    VAR Country_total1,Country_total2,Country_total3;
    FIX (@UDA(Entity,@ALIAS(@CONCATENATE("&Country",iloop)))) // &Country1, &Country2 - are substitution variables with UDAs stored as strings
    Statements;
    /* +<statements for calculating total values.. for that country and stored against variables>+ */
    Country_total1=Country_total1+ +<Calculation>+
    ENDFIX
    /* Second part : Now again the calculations stored in the variables are to be stored against specific entities */
    FIX (@UDA(Entity,@ALIAS(@CONCATENATE("&Country",iloop))))
    FIX(@ISUDA(Entity,<Check1>)
    ..... Assign to relevant account
    ENDFIX
    ENDFIX
    ENDLOOP
    ENDFIX
    Now the problem is that the first fix statement works just fine, but the FIX statement in the 'second part' throws an error
    Error: 1200354 Error parsing formula for [FIX STATEMENT] (line 66): expected type [STRING] found [EXTVAR] ([iloop]) in function [@CONCATENATE]
    If I hard code the 'second part' FIX statement to the substitution variable directly - it works just fine.
    How can the first statement work and not the second one ? They are exactly the same.

    Glenn, thanks - I hadn't thought of that :).
    But it still does not entirely solve my problem (please see my previous post depicting a requirement similar to ours )
    - We have lots of countries (50-60+ might be much more) and each country can have multiple entities (3-4 on an average - can go unto 7-8)
    - so good guess would be around 200 entities
    - So say I have to do it for 2 countries only (two entity types). Then I need 4 variables - 2 for each country ('country 1 ET1 total', 'Country 1 ET2 Total')
    When the list is 20 counties - variables become 40 :(.
    - Still leaving aside the 40 variables for a bit -
    There are subsequent steps of calculations which needs to be done based on these totals (which are exactly the same for all countries) - just that we need the correct totals to begin with and the rest is already stored in the DB
    So since I have a different variable for each country - I cannot write one single calculation block to use the variables sequentially one by one (can I ?)
    I might have to write a separate calculation block for each of these countries. (20 separate blocks)
    That's what I was trying to avoid and simplify with the substitution variable (but is not working)
    - Create substitution variables - which would store the alias of the required countries (2/10/20 as many required)
    - Loop through these substitution variables - using them one by one
    - So I just need one single block of calculation with all the variable in the calc script being reused after each country calculation is done
    - and the user need not go into the script, as the only thing that will change are the countries. And he can change it easily through the substitution variable.
    Edited by: Ankur on Jun 27, 2012 12:53 PM

Maybe you are looking for

  • Steps to UTF-8 Encoding with Oracle 8i and Weblogic 6.1SP1

    What are the Steps to UTF-8 Encoding with Oracle 8i and Weblogic           6.1SP1?           I have:           - Oracle 8.1.5 database created with character set=UTF8 and national           character set=UTF8           - Weblogic 6.1SP1 without any e

  • Set Message in BPM to System Error - Manual Restart Possible ?

    Hello, I'm working on a scenario where two idocs are merged in a BPM. The next step is sending the message in a synchronous RFC (BAPI) to a SAP R/3. Is it possible to set the merged message to the message status 'System Error - Manual Restart Possibl

  • How do I make image icons in finder window previews of the image?

    The image icons in my finder window are just generic jpeg icons (they are set to open automatically in Preview). How do I make them previews of the images themselves? When I "get info" on the icon, there is a very nice preview of the image - I would

  • JSP and Servlets? What's the difference?

    I've got this book, and it's mixing servlet with jsp and then jsp with servlet. Can we just use one and still make a web application? What is the difference between the both? Can anyone give me a basic idea behind these 2 J2ee technologies.

  • Epson NX400 sharing problem

    I have an Epson NX400 connected to a Mac Mini, and have it shared to my Macbook Air. It connects just fine, and will scan from the MBA. But when I do print, the document is at 50% normal size. It doesn't matter what kind of doc, it does it with all o