Accecpting something from the user inside PL-SQL
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 6 of 6

Thread: Accecpting something from the user inside PL-SQL

  1. #1
    Join Date
    Jan 2001
    Posts
    11
    Hi!!

    I want to do something like the following

    PROMPT Enter something please;
    ACCEPT my_answer;

    But inside a PL-SQL block. How can I do it? I could use DBMS_OUTPUT to replace the prompt, but what can I use instead of the ACCEPT ? (I search for a DBMS_InPUT package but that doesn't seem to exists :-) ).


    Any help would be appreciated!

    Wolf
    va2dax@hotmail.com

  2. #2
    Join Date
    Jan 2001
    Posts
    8

    Arrow

    Hello

    did you try using a substitution variable.
    Select ename, mgr from emp where empno = &eno;

    Here, eno is the substitution variable ( it is preceeded by a & to indicate that it is a substitution variable ) and oracle prompts the user to provide value for this variable. This may not be the exact alterntive to ACCEPT, but some what usefull in certain cases.

    Also i haven't figured out how to use the value the user had given for this sunstitution variable ( eno ) elsewhere in the PLSQL block. Using it as &eno will cause oracle to prompt again and using it as eno gave me errors.

    Hope this helps you,

    Cheers,
    Prasad
    Prasad

  3. #3
    Join Date
    Jul 2000
    Posts
    296
    You cannot use ACCEPT in PL/SQL.
    Is it possible to split your PL/SQL in two blocks, one before and one after the ACCEPT command? (As mentioned by Ad in the Development Forum).

    Or you can use a substitution variable, as Wolf mentioned.

    If you need the substitution variable (&your_variable) more then one time in your code, use double ampersands (&&your_variable) or asing it once to a variable you use in the rest of your code (my_used_variable := &my_substitition_variable).


  4. #4
    Join Date
    Jan 2001
    Posts
    11
    Thanks you two for your answers!!

    I try a substitution variable and it work, but I still have one problem:

    What I want to do is a validation loop, where my user enter a password until it is valid. The problem is, once I have given a value for my substitution variable, it stay the same, causing an infinite loop.

    Wolf
    Wolf
    va2dax@hotmail.com

  5. #5
    Join Date
    Jul 2000
    Posts
    296
    With the SQL*PLUS command:
    UNDEFINE your_substitution_variable
    you delete the substitution variable, a next time SQL*Plus finds the substitution variable it will ask for a value.

    Because UNDEFINE is a SQL*Plus command, like ACCEPT, you cannot use it in PL/SQL.

  6. #6
    Join Date
    Jan 2001
    Posts
    11
    Thanks everyone!

    Since what I try to do is a validaiton loop where the user enter a password until it is valid, I'm stuck inside a PL-SQL block. I guess that what I try to do isn't possible after all. :-(

    But thanks for your answers, it isn't lost! I have learned something new that could be useful another time.

    Wolf
    va2dax@hotmail.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width