Accepting dynamiv user input using PL/SQL

Hi,
I need to accept dynamic number of user input values.
What i need is i will enter the number of employees to be created.
If i enter 2 then i need to dynamically accept 2 employee details.
DECLARE
   v_emp_cnt    NUMBER;
   v_emp_id     VARCHAR2 (15);
   v_emp_name   VARCHAR2 (200);
BEGIN
   v_emp_cnt := &v_emp_cnt;
   FOR i IN 1 .. v_emp_Cnt
   LOOP
      DBMS_OUTPUT.PUT_LINE('INSIDE LOOP');
      v_emp_id := &v_emp_id;
      v_emp_desc := &v_emp_Desc;
      INSERT INTO emp_details (process_id,
                                        column11,
                                        column12,
                                        column13)
        VALUES   ('EMPLOYEES',
                  'EMP-' || i,
                  v_emp_id,
                  v_emp_desc);
   END LOOP;
END;
/Can anyone let me know if this is the right approach to acheive my requirement. Please suggest alternatives.
Thanks
Vamsi Krishna

PL/SQL is a server-side language-- it doesn't have the ability to interact with a user. A client application such as SQL*Plus, can both prompt for input and submit SQL statements to the database. It's probably possible to hack together a SQL*Plus script that could do something like what you appear to be looking for but using SQL*Plus for this sort of thing would generally be the wrong architectural solution. You'd generally be better off with a small shell script that prompted the user for data and then called a stored procedure.
Justin

Similar Messages

  • How to prompt for user input in PL/SQL

    How do I prompt for user input in PL/SQL?
    I am writing a piece of code where the user may choose, by clicking either of three buttons on an alert, to have the system assign a value to a variable, to input a value or to do neither?
    If the user chooses to input the value I want to update a set of database fields with the value.
    I have thought about showing a view where the value may be entered into a field displayed on that view. The value will be assigned to the variable by the user clicking a command button. The question I have in this case though, is whether, after the command button is clicked, control will be passed back to the code that called the view in the first place?
    Edited by: desgordon on Sep 3, 2008 10:33 AM

    desgordon wrote:
    How do I prompt for user input in PL/SQL?
    I am writing a piece of code where the user may choose, by clicking either of three buttons on an alert, to have the system assign a value to a variable, to input a value or to do neither?OK, you're doing that in Forms...
    >
    If the user chooses to input the value I want to update a set of database fields with the value.Write PL/SQL procedure for this purpose...
    >
    I have thought about showing a view where the value may be entered into a field displayed on that view. The value will be assigned to the variable by the user clicking a command button. The question I have in this case though, is whether, after the command button is clicked, control will be passed back to the code that called the view in the first place?Not clear what you mean with view?
    But if you call your procedure in that button then yes 'control will be passed back to the code'...
    Cheers!
    Edited by: Faust on Sep 3, 2008 7:57 PM
    Too slow...

  • User input from pl/sql

    How could I get user input from a pl/sql block?
    Hope that somebody can help me.
    thanx
    Amelio.

    There is a package DBMS_LOCK that has a SLEEP routine, which suspends the session for a given period of time (in seconds).
    However, you can only pause the procedure and not accept user input into the procedure during the pause.
    syntax: DBMS_LOCK.SLEEP(1) ;
    I need only to run an 'pause' or something like that within a pl/sql block. Do you know if it's possible? Thanks.

  • Creating a user with "create user" privilege using PL/SQL?

    I have managed to use the PL/SQL DBMS_LDAP package to create and modify OID users (DBMS_LDAP.add_s and DBMS_LDAP.modify_s).
    The question is: How can I use DBMS_LDAP to assign privileges to OID users? By "privileges" I mean options like the following (i.e. the options you can enable/disable for any OID user if you login to OIDDAS and click the "privileges" button for a particular user):
    Allow user creation
    Allow user editing
    Allow user deletion
    Allow group creation
    Allow group editing
    Allow group deletion
    Allow privilege assignment to users
    Allow privilege assignment to groups
    Andy

    Solution found.
    In case anyone comes back to this thread in the future looking to achieve a similar thing: Metalink 205315.1 contains details.

  • Worklist: User Input using UI rather than supplying XML

     

    I'm not sure I understand your exact question, but in general, the
    worklist manager is accessed via the Task and Task Worker controls.
    In BEA WLI, you would add a Task Worker control to your Pageflow and use
    it to work with created tasks.
    The Task control is used to create tasks inside a Process.
    Steve
    Rashmi wrote:
    Hi,
    I went through the tutorial for Worklist for WLI.
    In the example the input from the user was received using XML, if I want to provide
    a User Interface (JSP) for submitting such input, is it possible? If so how can
    it be done using WLI? Any refrences will be highly appreciated.
    Thanks
    Rashmi

  • How to accept user inputs from  sql script

    I want to create Tablespace useing sql script , but the location of the data file I need accept from user . (to get the location of the data file ) .
    How can I accept user input from pl/sql .
    Example :
      CREATE TABLESPACE  TSPACE_INDIA LOGGING
         DATAFILE 'H:\ORACLE_DATA\FRSDB\TSPACE_INDI_D1_01.dbf'
         SIZE 500M  AUTOEXTEND ON NEXT  1280K MAXSIZE UNLIMITED
         EXTENT MANAGEMENT LOCAL;here I need to accept location of the datafile from user ie : 'H:\ORACLE_DATA\FRSDB\TSPACE_INDI_D1_01.dbf'

    Hi,
    Whenenever you write dynamic SQL, put the SQL text into a variable. During development, display the variable instead of executing it. If it looks okay, then you can try executing it in addition to displaying it. When you're finished testing, then you can comment out or delete the display.
    For example:
    SET     SERVEROUTPUT     ON
    DECLARE
        flocation     VARCHAR2 (300);
        sql_txt     VARCHAR2 (1000);
    BEGIN
        SELECT  '&Enter_The_Path'
        INTO    flocation
        FROM    dual;
        sql_txt :=  'CREATE TABLESPACE SRC_TSPACE_INDIA LOGGING
         DATAFILE' || flocation || ' "\SRC_TSPACE_INDI_D1_01.dbf" ' || '
         SIZE 500M  AUTOEXTEND ON NEXT  1280K MAXSIZE UNLIMITED
         EXTENT MANAGEMENT LOCAL ';
        dbms_output.put_line (sql_txt || ' = sql_txt');
    --  EXECUTE IMMEDIATE sql_txt;
    END;
    /When you run it, you'll see something like this:
    Enter value for enter_the_path: c:\d\fubar
    old   5:     SELECT  '&Enter_The_Path'
    new   5:     SELECT  'c:\d\fubar'
    CREATE TABLESPACE SRC_TSPACE_INDIA LOGGING
         DATAFILEc:\d\fubar
    "\SRC_TSPACE_INDI_D1_01.dbf"
         SIZE 500M  AUTOEXTEND ON NEXT  1280K MAXSIZE
    UNLIMITED
         EXTENT MANAGEMENT LOCAL  = sql_txt
    PL/SQL procedure successfully completed.This makes it easy to see that you're missing a space after the keyword DATAFILE. There are other errrors, too. For example, the path name has to be inside the quotes with the file name, without a line-feed between them, and the quotes should be single-quotes, not double-quotes.
    Is there some reason why you're using PL/SQL? In SQL, you can just say:
    CREATE TABLESPACE SRC_TSPACE_INDIA LOGGING
    DATAFILE  '&Enter_The_Path\SRC_TSPACE_INDI_D1_01.dbf'
    SIZE 500M  AUTOEXTEND ON NEXT  1280K MAXSIZE UNLIMITED
    EXTENT MANAGEMENT LOCAL;though I would use an ACCEPT command to given a better prompt.
    Given that you want to use PL/SQL, you could assign the value above to sql_txt. If you need a separate PL/SQL variable for flocation, then you can assign it without using dual, for example:
    DECLARE
        flocation     VARCHAR2 (300)     := '&Enter_The_Path';The dual table isn't needed very much in PL/SQL.
    Edited by: Frank Kulash on Jan 10, 2013 6:56 AM

  • User interaction in pl/sql

    hi!!
    just wanna know how to accept user input in sql plus using pl/sql??
    if i prompt a question "Are u happy today?(Y/N)"
    how do i receive user's answer?
    thanks..

    Hi,
    sueazri wrote:
    hi!!
    just wanna know how to accept user input in sql plus using pl/sql??
    if i prompt a question "Are u happy today?(Y/N)"
    how do i receive user's answer?
    thanks..Sorry, you can't. There's no user input in PL/SQL.
    You can use the SQL*Plus ACCEPT command to prompt the user for a value that gets stored in a substitution variable. You can then use that substitution variable in PL/SQL, but it will be resolved before the PL/SQL is compiled, not at run-time.
    For example:
    ACCEPT     happy_y_n     PROMPT "Are you happy today? (Y/N): "
    SET     SERVEROUTPUT     ON
    CREATE OR REPLACE PROCEDURE     happy_message
    IS
    BEGIN
         IF  UPPER ('&happy_y_n') LIKE 'Y%'
         THEN
              dbms_output.put_line ('That''s great!');
         ELSE
              dbms_output.put_line ('Hope you feel better soon.');
         END IF;
    END     happy_message
    /will create a procedure, but the user input is performed when you run the script above. When you execute the procedure, it uses whatever value the substitution variable &happy_y_n had when you compiled the procedure: it doesn't ask anything at run-time.
    Other front-end tools (such as Forms) have their own ways of getting user input (such as dialogue windows).
    Edited by: Frank Kulash on Mar 8, 2010 10:24 PM
    Added example.

  • User Input in PLSQL

    Hi everyone
    One of my customer wants me to write a PLSQL procedure which allows to take input from a user and then insert values into the table.
    I know the 2nd part i.e. insert values into the table in PLSQL procedure but not sure about the first part i.e. taken input from user in PLSQL.
    Regards
    Muhammad Ali

    Hi, Muhammad,
    User input in PL/SQL is very simple: there is none.
    Use your front-end tool to propmt the user for get input, put the input in a variable, and pass the variable to your PL/SQL code (usually as an argument, though there are other ways too).
    Can you say in more detail what you need to do?

  • Capturing and displaying user input in Crystal Reports

    Hi all,
    Iu2019m creating a crystal report with SAP as data-source and want to capture user input and display it on the report.  I have defined parameters to capture the input and added them to the report header.   I have then created formula fields to capture user input using the JOIN statement to accommodate multiple values.   Everything works well when users enter values for all the parameters, but when they leave some blank I get an error message u201CParameter value is nullu201D.
    Has anyone encountered this type of problem;  Anyone knows how to resolve this?

    Hi
    In parameter window make the Optional prompt to True.  And change make change in your record selection formula like this :
    (not HasValue({?PrjMgr@SELECT Firstname,lastname FROM OHEM}) OR
    ISNULL({?PrjMgr@SELECT Firstname,lastname FROM OHEM}) OR
    ({?PrjMgr@SELECT Firstname,lastname FROM OHEM} = '') OR
    {OHEM.firstName} = {?PrjMgr@SELECT Firstname,lastname FROM OHEM})
    Regards

  • Check User inputs ( sap.m.input / sap.m.inputType )

    Hi there,
    I'm trying to check user inputs using sap.m.inputs.
    I want my inputs' state to be changed when their value breaks a constraint.
    For example :
    <input type="Number" .../> => Value is "Azerty" => Error, control's valueStat = Error, the inputs becomes red ( as in the example).
    <input type="Number" ... value="{  path:'Id',  type: 'sap.ui.model.type.Integer',  constraints: {  minimum : 0,                                             maximum : 3 }   } /> => Value is "4" => Error
    My view is binded to an odatamodel, and described as below  :
    <core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"
        xmlns="sap.m" xmlns:form="sap.ui.layout.form" controllerName="fioriform.manufacturerFormPage"
        xmlns:html="http://www.w3.org/1999/xhtml">
        <Page title="Manufacturer" showNavButton="false" navButtonPress="handleNavButtonPress">
            <content>
                <form:Form id="aForm">
                    <form:formContainers>
                        <form:FormContainer>
                            <form:formElements>
                                <form:FormElement>
                                    <form:label>
                                        <Label text="Id" />
                                    </form:label>
                                    <form:fields>
                                        <Input id="inputId" type="Number" placeholder="Enter an id" maxDigit="2"
                                            valueStateText="Maximum 3 digits."
                                            value="{
                                                path:'Id',
                                                type: 'sap.ui.model.type.Integer',
                                                constraints: {
                                                    minimum : 0,
                                                    maximum : 3
                                                }" />
                                    </form:fields>
                                </form:FormElement>
                                <form:FormElement>
                                    <form:label>
                                        <Label text="Name" />
                                    </form:label>
                                    <form:fields>
                                    <Input id="testMail" type="Email" valueStateText="Fail." />
                                    <Input id="nameInput"
                                     type="Text"
                                     placeholder="Enter Name ..."
                                     valueStateText="Name must not be empty. Maximum 10 characters."
                                     value="{
                                         path:'',
                                         type:'sap.ui.model.type.String',
                                         constraints : {
                                             minLength: 1,
                                             maxLength: 10
                                         }"/>
                                        <Input id="inputName" type="Text" placeholder="Enter a manufacturer name"
                                        valueStateText="Name must not be empty. Maximum 10 characters."
                                            value="{
                                                 path : 'Name',
                                                  type: 'sap.ui.model.type.String',
                                                   contraints:'{minLength:1 , maxLength:10}'
                                            />
                                    </form:fields>
                                </form:FormElement>
                                <form:FormElement>
                                    <form:label>
                                        <Label text="Street" />
                                    </form:label>
                                    <form:fields>
                                        <Input id="inputStreet" type="Text" placeholder="Enter the street"
                                            value="{Address/Street}" />
                                    </form:fields>
                                </form:FormElement>
                                <form:FormElement>
                                    <form:label>
                                        <Label text="City / Zipcode" />
                                    </form:label>
                                    <form:fields>
                                        <Input id="inputCity" type="Text" placeholder="Enter city"
                                            value="{Address/City}" />
                                        <Input id="inputZipCode" type="Text" placeholder="Enter zipcode"
                                            maxLength="6" value="{Address/ZipCode}" />
                                    </form:fields>
                                </form:FormElement>
                                <form:FormElement>
                                    <Button text="Save" press="handleSave" />
                                </form:FormElement>
                            </form:formElements>
                        </form:FormContainer>
                    </form:formContainers>
                    <form:title>
                        <core:Title text="Manufacturer edit" />
                    </form:title>
                    <form:layout>
                        <form:ResponsiveGridLayout />
                    </form:layout>
                </form:Form>
            </content>
        </Page>
    </core:View>
    I have already checked : sap.m Explored  - Checked  and sap.m Explored Types.
    I have tried to attach some functions to the core as : sap.ui.getCore().attachValidationSuccess, sap.ui.getCore().attachParseError, sap.ui.getCore().attachValidationError but without being successful ( no one is called ).
    I have also tried to call a function onChange ( <Input ... change="myFunction"/> ) but i need to rewrite what UI5 seems to check and do alone.
    None of my inputs works except Email even if its behavior it's strange. It becomes red when an email is not well entered, but the displayed text is not "Fail", it is the standard message.
    I do not understand those mechanics. Can someone explain it to me?
    Thanks for Helping,
    Regards,
    Marc

    i will try this then i come back yo you.
    Thanks,
    Regards,
    Marc
    edit: it works but like i said before, i do not want to rewrite what UI5 seems to do alone - when specifiing types and values -.
    I would like somebody to help me out in my ignorance here.
    Message was edited by: Marc BROSSAIS

  • Accepting user input and executing a PL/SQL block using it

    Hi All,
    I am working on a requirement wherein I have to accept values from the user for the various arguments to be supplied to a PL/SQL block and then execute it using these values. For now, I am using the following logic:
    PROMPT Enter value for the Category
    ACCEPT cCategory CHAR PROMPT 'Category:'
    DECLARE
    cCategry CHAR(1) := '&cCategory';
    BEGIN
    DBMS_OUTPUT.PUT_LINE('The value of the Category as entered by you is' || cCategory);
    END;
    PROMPT Press y if you want to proceed with the current values, or press n if you want to re-enter the values
    ACCEPT cChoice CHAR Prompt 'Enter y or n:'
    DECLARE
    cCategry CHAR(1) := '&cCategory';
    sErrorCd VARCHAR2(256);
    sErrorDsc VARCHAR2(256);
    BEGIN
    IF '&cChoice' = 'y'
    THEN
    DBMS_OUTPUT.PUT_LINE('Starting with the process to execute the stored proc');
    --- schema1.package1.sp1(cCategry, sErrorCd, sErrorDsc);
    --- DBMS_OUTPUT.PUT_LINE('Error Code :' || sErrorCd);
    --- DBMS_OUTPUT.PUT_LINE(' Error Description :' || sErrorDsc);
    ELSIF '&cChoice' = 'n'
    THEN
    Now I want that the proc again start executing in the loop from the 1st line i.e. PROMPT Enter value for the Category. However i see that this is not possible to do that PROMPT statements and accepting user inputs execute only on the SQL prompt and not inside a PL/SQL block.
    Is there an alternate method to establish this?
    Thanks in advance.

    Hi,
    You can write a genric procedure to achive the desired output. Pass 'Y' or 'N' in the procedure.
    Call that procedure in simple pl/sql block during runtime using substituton operator.
    For ex
    create or replace procedure p1(category_in in varchar2)
    IS
    BEGIN
    if (category_in='Y')
    then
    prcdr1()
    /** Write your logic here ***/
    elsif(category_in='N') then
    prcdr2()
    /** write your logic here***/
    end if;
    exception
    /***write the exception logic ***/
    end p1;
    Begin
    p1('&cat');
    end;Regards,
    Achyut K
    Edited by: Achyut K on Aug 6, 2010 5:20 AM

  • How to use Pl/sql block to edit check user input

    Hi,
    Please advise on PL/SQL Block code that could be used to Check User input from within a Loop and proceed conditionally based upon User Supplied compliant Input. Thanks in advance.

    Hi,
    yakub21 wrote:
    You could use the ACCEPT to get user input and then assign the input to a variable that could then be verified.
    I believe that anything is possible because we don't yet have proof that it is not!
    I do have code that can accept user input. Is it PL/SQL code? Sybrand was clearly talking about PL/SQL:
    sybrand_b wrote:
    Pl/sql is for server side code, it is not a front end tool, and it is incapable of the functionality you describe.If you do have PL/SQL code that accepts user input, please post an example. A lot of people, including me, would be very interested.
    Pass the user-input value to a variable and then assign that value to another variable from within a Declare of a PL/SQL Block.
    The opportunity here is to figure a way to loop with user input until desired input is entered by the user before proceeding with the code. I'm using PL/SQL Block because I don't want the code to persist. I just want to run it as part of database configuration procedure. ThanksIt sounds like you're talking about SQL*Plus, which is a very poor tool for looping or branching.
    It's possible, but it's not pretty. The following thread shows one way of looping in SQL*Plus:
    Re: How to give the different values to runtime parameters in a loop?

  • Generating DDL to accept user input parameters

    I need generate DDL which will accept input parameters from user, for example, tablespace name for indexes. What is the best way to do it?
    At present, I’ve created tablespace with name ‘&INDEX_TS’ in physical model and using it to create indexes. Is this a correct way to do it?
    Also, &INDEX_TS appears within double quotes in generated DDL. Is there a way to get rid of double quotes?
    I'm using v3.1

    Hi,
    I have just found out that there is a "substitution variable" facility within SQL*Plus and SQL Developer which allows runtime substitution when applying DDL.
    Here are some extracts from the SQL Developer Help:
    Script Runner
    The SQL*Plus features available in the script runner include @, @@, CONNECT, EXIT, QUIT, UNDEFINE, WHENEVER, and substitution variables. For example, to run a script named c:\myscripts\mytest.sql, type @c:\myscripts\mytest in the Enter SQL Statement box, and click the drop-down next to the Execute Statement icon and select Run Script.
    The following considerations apply to using the SQL Developer script runner:
    For substitution variables, the syntax &&variable assigns a permanent variable value, and the syntax &variable assigns a temporary (not stored) variable value.
    So if the name starts with &&, it will only prompt for the actual name the first time it appears.
    Note that this still works if the name is presented as a quoted identifier, e.g.
    TABLESPACE "&&INDEX_TS"
    David

  • User input in SQL /PL-SQL

    Can I take the user input in SQL or PL/SQL please tell the procedure how can I do that suppose I am interested to get the information of the employee by respect to his age where age will be the user input (any person who will run the query prompted that enter the age)

    in PL/SQL you cannot make any terminal input because PL/SQL is running only on server side and has not been designed to handle such kind of input.
    With SQL*Plus, you can use PROMPT, ACCEPT instructions: see
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch5.htm#sthref1089

  • Accept user input

    Dear All,
    How do we accept user input in isql*plus in 9i? I am writing pl/sql code that requires user input but i get the message:
    SP2-0850: Command "accept" is not available in iSQL*Plus
    the figure you requested is:
    PL/SQL procedure successfully completed.

    Also you can use some commands at sqlplus to add/delete/append lines of sql buffer.
    append (a)
    insert (i)
    del (d)
    run (r)iline (l) nth line (1l or 2l ...)
    change c/<old value>/<new value>
    etc.,
    << Sample >>
    SRI>select * from bonus;
    ENAME JOB SAL COMM
    Sri DBA 1000 123
    Sam Sales 1022 10
    Elapsed: 00:00:00.00
    SRI>c/*/ename,job
    1* select ename,job from bonus
    SRI>r
    1* select ename,job from bonus
    ENAME JOB
    Sri DBA
    Sam Sales
    Elapsed: 00:00:00.01
    SRI>i
    2 where ename = 'Sri';
    ENAME JOB
    Sri DBA
    Elapsed: 00:00:00.01
    SRI>;
    1 select ename,job from bonus
    2* where ename = 'Sri'
    SRI>2
    2* where ename = 'Sri'
    SRI>DEL
    SRI>;
    1* select ename,job from bonus
    -Sri

Maybe you are looking for

  • In desperate need of config assistance for 6513 trunking to Netapp controller

    We are building a new SAN using a Netapp Fas3160 with 2 controllers in failover mode. We have 1 6513 switch they will connect to for the etherchannels. Each Netapp controller will need an LACP port channel with 4 gig interfaces in each running to the

  • URGENT: issue while creating user through reconciliation of AD

    Hi, We have a requirement where we need to create users in IDM through reconcilition against Active Directory. For certain type of account Ids I want to trigger a custom workflow used for user creation. So I set "viewOptions.Process" to my custom wor

  • How to make a water reflection?

    I have a picture that I want it to look like its sitting in the water how can I do this I have no clue is there water reflection effects in AS3 Flash?  If there is can I have an example?

  • Editing frames in PSE8

    Hi guys, I wondered if it is possible to edit/ to adjust existing frames. I found this article about PSE 6 ( http://www.alibony.com/pse/012208frame.html ), but these options seems to not be there in later versions. thx, D.

  • Please help me with export settings and format

    I'll try to explain my problem the best I can. I recently captured some footage from old VHS tapes to use in a Christmas video. I imported one of the MPGs that I captured to AE and applied a grain removal plus a couple other lighting effects to the v