Accept user input in sql *plus 9.2.0.1.0

Any body budy can get any idea about my sourcr code?
I wrote below code in sql *plus
accept p_hire_date1 date FORMAT 'DD-MON-YYYY' prompt 'ENTER hire date from:'
accept p_hire_date2 date FORMAT 'DD-MON-YYYY' prompt 'ENTER hire date to:'
DECLARE
v_hd1 employees.hire_date%TYPE := TO_DATE(&p_hire_date1);
v_hd2 employees.hire_date%TYPE := TO_DATE(&p_hire_date2);
CURSOR emp_cursor IS
SELECT e.last_name, e.first_name, e.hire_date, e.salary, d.department_name
FROM employees e, departments d
WHERE ((e.hire_date>=v_hd1) AND (e.hire_date<=v_hd2)) AND
(e.department_id=d.department_id)
ORDER BY e.first_name;
emp_record emp_cursor%ROWTYPE;
BEGIN
DBMS_OUTPUT.ENABLE
DBMS_OUTPUT.PUT_LINE(RPAD('Name',20) || RPAD('Hire Date',15) || RPAD('Salary',15) || RPAD('Dept. name',15));
DBMS_OUTPUT.PUT_LINE(RPAD('-',4*15,'-'));
FOR emp_record IN emp_cursor
LOOP
DBMS_OUTPUT.PUT_LINE(RPAD(emp_record.first_name || ' ' || emp_record.last_name,20) || RPAD(TO_CHAR(emp_record.hire_date),15) || RPAD(TO_CHAR(emp_record.salary),15) || RPAD(emp_record.department_name,15) );
END LOOP;
END;
when I execute it I got this error
SQL> /
Enter value for p_hire_date2: 23
accept p_hire_date1 date FORMAT 'DD-MON-YYYY' prompt 'ENTER hire date from:'
ERROR at line 2:
ORA-00900: invalid SQL statement
any Idea?

Your "accept" statement seems to be correct.
Please change the declaration of v_hd1 and v_hd2 as below.
v_hd1 employees.hire_date%TYPE := TO_DATE('&p_hire_date1','DD-MON-YYYY');
v_hd2 employees.hire_date%TYPE := TO_DATE('&p_hire_date2','DD-MON-YYYY');
Since p_hire_date1 and p_hire_date2 are date variables enter a valid date of format DD-MON-YYYY. You have entered 23 which is not a valid date.

Similar Messages

  • Accepting User input in SQL*Plus

    I am writing a SQL script in SQL*Plus that accepts a value from the user and plugs that value into a variable that exist in several locations outside of the PL/SQL block.
    I am able to do this, yet everytime this variable is encountered, the user is prompted for input. I would like to have the user prompted only once at the beginning and then use that value throughout. This seems like a simple task, yet I cannot get it to work.
    Any help would be greatly appreciated.

    You can use &&<variable_name> and it will define the variable and use it throughout the SQL code.

  • 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

  • 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

  • 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

  • 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

  • Failed to accept user input when run report on Web

    I've testing a report with one input parameter. It's a date with default current date. It is done by using SQL 'select sysdate from dual;' has been added to before form trigger. User is allowed to input any date other than the default sysdate before submitting the report. The report works fine when run in report builder, but it's failed to accepted user input date when called through web browser. The report still uses the current date as SQL parameter rather than user input date.
    Can anyone help me to fix this bug?
    The report is develped by Oracle 9i and is saved and run in .rdf format.

    I created a report with a user defined parameter p_date of DATE type. In the layout model, I created a field with p_date as data source. In the before form trigger, I put
    'select sysdate into :p_date from dual;
    I run the report through rwservlet:
    http://host:port/reports/rwservlet?report=datetest.rdf&destype=cache&desformat=html&userid=scott/tiger@orcl&paramform=yes
    In the html parameter form, I change the date from default current date to a future date and that date is shown in the final report.
    So I can't reproduce the bug.
    One thing you can try it to turn on reports server trace file, see what command line is sent to reports server when you submitting the parameter form.
    Thanks,
    -Shaun

  • 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

  • Input with sql*plus and Output it with PL/SQL

    Hi everyone,
    I try to understand how can I get input and input by using sqlplus and plsql together. I get output like this:
    Get User Input
    Given Name: Iron
    Family Name: Man
    old   6:        Given_Name := '&GivenName';
    new   6:        Given_Name := 'Iron';
    old   7:        Family_Name := '&FamilyName';
    new   7:        Family_Name := 'Man';
    Given Name: Iron
    Family Name: Man
    PL/SQL procedure successfully completed.My Codes:
    PROMPT Get User Input
    ACCEPT GivenName PROMPT "Given Name: "
    ACCEPT FamilyName PROMPT "Family Name: "
    DECLARE
         Family_Name Varchar(15);
         Given_Name Varchar(15);
    BEGIN
         Given_Name := '&GivenName';
         Family_Name := '&FamilyName';
         DBMS_OUTPUT.PUT_LINE('Given Name: ' || Given_Name); 
         DBMS_OUTPUT.PUT_LINE('Family Name: ' || Family_Name);
    END;
    /My question is why I get
    old   6:        Given_Name := '&GivenName';
    new   6:        Given_Name := 'Iron';
    old   7:        Family_Name := '&FamilyName';
    new   7:        Family_Name := 'Man';this bit?Is there something wrong in my code? Thanks.

    Hi,
    From SQL*Plus reference:
    After you enter a value at the prompt, SQL*Plus lists the line containing the substitution variable twice: once before substituting the value you enter and once after substitution. You can suppress this listing by setting the SET command variable VERIFY to OFF.
    So. you can remove current output with
    SET VERIFY OFF
    and enable your PL/SQL output by
    SET SERVEROUTPUT ON
    Regards
    Peter

  • Prompt For User Input in SQL Developer

    I am using the '&' in a very basic SQL select script, but I do not get a prompt for my input. However, i have used the '&' in update scripts and it does prompt me.
    For example:
    select DCC_DESCRIPTION
    from S_TBLDTMINOR
    where DCC_DTMINOR = &Minor;
    Gives an ORA-01008 error (not all variables bound).
    If it's a varchar field and I use '&Minor' - it executes with no error, but does not prompt for data. Please note:  this script works when it's run in SQL*Plus, but not in SQL Developer.
    If I execute:
    update S_TBLDTMINOR
    set DCC_DESCRIPTION = 'Mark & Wilson'
    where DCC_DTMINOR = 'AAA';
    It does prompt me for a value (but I do not want it to).
    So I know prompting works in SQL Developer, but it does not work in select statements.
    Is this a configuration setting I can change in SQL Developer? I know I can use the escape in the update statement to avoid the prompt, but I'm not concerned with that. I'm trying to get the prompting to work in the select statement.
    Edited by: user12289057 on Feb 23, 2012 11:17 AM

    Hi user12289057,
    1/Not sure what your testcase is (including table definition), I was trying to reproduce with:
    select * from dual where dummy = '&myin'
    2/Try
    undefine Minor
    to ensure Minor is not already set.
    3/Minor may need to be quoted if it is a string.
    Short blog post on substitution and bind variables.
    http://totierne.blogspot.com/2010/04/substitution-and-bind-variables.html
    -Turloch
    SQLDeveloper team.

  • User name in sql*plus

    hi there
    I want to know if we can store the user by which one has logged in sql*plus .
    like if I want to store the names , times etc of all the users who logged into oracle using SQL*PLus can I store the name in a varible and insert into a table afterwards..
    thankx
    dg

    There is an environment variable USER that you can use. (select USER from dual).
    null

  • SQLPATH for user profile of SQL*PLUS

    Hi there,
    I am using 9.2 on HPUX. I tried set up my user profile script (login.sql) and place it in a place included in SQLPATH variable. It worked in 8.1.x but not in 9.2
    Is it an identified bug? I have no access to metalink

    Seems to work on my windows environment.
    E:\>set SQLPATH=C:\Temp
    E:\>
    E:\>mkdir C:\Temp\Help
    E:\>
    E:\>echo prompt Help... > C:\Temp\Help\Help.sql
    E:\>
    E:\>sqlplus
    SQL*Plus: Release 9.2.0.3.0 - Production on Thu Sep 25 23:08:40 2003
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Enter user-name: /
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.3.0 - Production
    SQL>
    SQL> @Help\Help.sql
    Help...
    SQL>
    SQL> @Temp\Help\Help.sql
    Help...
    SQL>
    SQL> exit
    Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.3.0 - Production
    E:\>

  • After "Hello World" - my first adventure in accepting user input

    Hey
    I'm trying to teach myself java and I'm attempting to move on from printing hello world to the screen :)
    I've written the following:
    import java.io.*;
    public class firstapp {
         int value1,
              value2,
              result;
         public static int add(int value1, int value2){
             return value1 + value2;
         public static void main(String args[]){
              int value1,
                        value2,
                        result;
              BufferedReader reader;
              reader = new BufferedReader(new InputStreamReader(System.in));
              //try block
              try{
                   System.out.println("Please type the first number");
                   value1 = reader.read();
                   System.out.println("Please type the second number");
                   value2 = reader.read();
                   result = add(value1,value2);
                   System.out.println("Added together they equal " + result);
         catch (IOException ioe){
              System.out.println("Something bad happened");{
         }It doesnt do what I expected though. It prompts for the first number which i enter. It then prints "Please type the second number" but doesnt accept any input and goes on to print "Added together they equal 62" (this is when 1 is entered as the first number).
    Im so new to this so excuse it being the most basic of basic questions. But where is it getting 62 from?
    Thanks

    BufferedReader.read() isn't the best method for this. It reads a single character, which you store as an int. If you entered "5" for example, the ascii value of 5 is being stored, not the value 5. The second read() call is most likely reading the carriage return, so it adds 53 and 13, and prints that out, for example. If you have version 1.5 or better, use the Scanner class instead, it has a nextInt() method that does what you want.

  • URGENT!.....accepting user input and string conversion

    I have a problem with a text-based menu I am trying to create for a Shape class with rectangle, circle, etc... subclasses below it...here is a code clip
    //The menu choices given to the user.
              System.out.println("Please select which shape you would like to create:\n");
              System.out.println("(1)Rectangle");
              System.out.println("(2)Square");
              System.out.println("(3)Circle");
              System.out.println("(4)Ellipse");
              System.out.println("(5)Exit the program\n");
              System.out.print("Enter your choice (1,2,3,4 or 5): ");
         menuChoice=(char)System.in.read();
    switch(menuChoice) {
    case '1':                              
    System.out.println("\nTo create a rectangle, please enter the following dimensions below (integers only)...\n");                    
         System.out.print("Center X co-ordinate = ");
              while((x=(char)System.in.read()) !='\n')
              CentXBuf.append(x);     
         System.out.print("Center Y co-ordinate = ");
              while((y=(char)System.in.read()) !='\n')
              CentYBuf.append(y);
    The above works fine, however, when the the user inputs the menu choice, it does not let me input the center x co-ordinate and goes on to the second input of the center y co-ordinate then the program crashes with a NumberFormatException
    I tried to replace
         menuChoice=(char)System.in.read();
    with
         while((z=(char)System.in.read()) !='\n'){
              zBuff.append(z);
         String v = new String(zBuff);
         int menuChoice = Integer.valueOf(v).intValue();
    but the above itself gives me a NumberFormatException also!
    What do I do?!?!

    Try this:
    BufferedReader reader = new BufferedReader(
    new InputStreamReader(System.in)
    String input = reader.readLine();

  • User Input With SQL?

    Hi
    I need to create a query that uses user input as part of the query.
    Example:
    SELECT * FROM item
    WHERE designer = 'Gucci';
    The 'Gucci' part of the query needs to be user input every time the query is ran... Can you help?
    I've tryed the following, but it does not work....
    SELECT * FROM Item
    WHERE Designer like '&& Designer';
    All help appreciated, thanks.

    Hello,
    Try this and if you don't want to specify single quote then at the prompt user have to enter like 'Gucci'. And with the following statement user just have to enter Gucci at the prompt
    SELECT * FROM Item
    WHERE Designer like ('&Designer');Regards

Maybe you are looking for

  • Daily per diem handling

    Hi friends, My per diem requirements are as below: Example scenario: Travel from Singapore >Bangkok>Japan>Singapore Employee travels from Singapore on 17.12.2009 and arrives in Bangkok on the same day. Flies from Bangkok on 18.12.2009 and arrives in

  • Could we attach all received quotes to a PO

    Is there a way we could attach all quotes to a PO? Managers would like to see all quotes that have come in before approving the PO.

  • Need to update iPod through itunes 7.0

    I havent updated my ipod in a while and i am trying to update it on my new computer. i plug in my ipod and it isnt reconized by my computer or itunes..nothing happens and the do not disconnect does not come up on my ipod screen. i put in my ipod+itun

  • Send HTTP response to browser

    I am working on an applet for use in HTML forms that acts like an HTML submit button, but does some processing of the data before POSTing it to the server. I have it working, but I would like to send the HTTP response back to the browser instead of r

  • Importing Final Cut XML Hangs Premiere Pro CC 2014

    I am posting this more as a question as to how to report hangs or console reports of PP crashes. I have a Final Cut Pro project that I wanted to migrate to Premiere Pro using the XML route. When I import the XML from Final Cut, the app hangs with a s