Prompting a user input help

Ok, I am working on my first database and I am trying to create an end-user intput to populate my table. I have created a before insert trigger that should automatically populate two fields.
Here it is:
SQL> CREATE OR REPLACE TRIGGER emp_update
2 BEFORE UPDATE OR INSERT ON emptemp
3 FOR EACH ROW
4 BEGIN
5 :NEW.Annual_Salary:=26*80*:NEW.Hourly_Rate;
6 :NEW.Employee_Code:=SUBSTR(:NEW.Last_Name,1,3)||
7 SUBSTR(:NEW.Employee_SSN,-5);
8 END emp_update;
9 /
Trigger created.
SQL>
I'm not very comfortable writing code yet and I need to create a program that will prompt a user to input the other fields in my table (First_name, Last_Name, SSN, Hourly_Rate etc.) Once They input the data I need my trigger to kick off to fill in the two fields that it references.

If this is a "real" project, rather than something like a school assignment where the professor is asking you to learn about SQL*Plus, I'd strongly recommend not using SQL*Plus here.
SQL*Plus is not designed as a front end to interact with users. While it has some limited abilities to accept input and pass that to PL/SQL, it's at best clunky. My guess is that you'd be much happier doing something like writing a small APEX application that has fields to fill out with the information you want and which then does the insert.
Going even further, if this is a real program, I'd suggest that you write a stored procedure that takes the 4 parameters and incorporates the trigger logic to populate the other column and have your program call this procedure rather than doing a direct insert. That way, you can grant other users EXECUTE access on this procedure without having to give them the ability to directly manipulate the table.
Justin

Similar Messages

  • How to prompt for user input in Forms

    How do I prompt for user input in Forms?
    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?

    Desgordon,
    This can be accomplished by displaying your message to the user using an Alert. I use 3 different Alerts (Note, Caution and Stop) in my forms and they are inherited from a central source file (such as an Object Library or a Template Form) so they can be used by all of my Forms. You can set the text of the Alert using the SET_ALERT_PROPERTY() built-in and capture what button the user presses with the SHOW_ALERT() built-in. Additionally, if you need more than one button to be displayed in an alert, you use the SET_ALERT_BUTTON_PROPERTY() built-in to rename the default button or to add up to a total of three buttons in the alert. Here's an example:
    DECLARE
       Alert_ID       ALERT;
       v_AlertType    VARCHAR2(10) := 'CAUTION';
       v_AlertTitle     VARCHAR2(25);
       v_AlertText    VARCHAR2(150);
       n_AlertButton  NUMBER;
    BEGIN
       v_AlertTitle := 'Title of Alert';
       v_AlertText := 'This is message to the user.';
       /* Code leading up to the decision point. */
       alert_id := FIND_ALERT(v_AlertType);
       /* Note: I only set the Label of Button 2 because the default button 1 label is 'OK' */
       SET_ALERT_BUTTON_PROPERTY(v_AlertType, ALERT_BUTTON2, LABEL, 'Cancel');
       SET_ALERT_PROPERTY(Alert_ID, v_AlertTitle, v_AlertText);
       n_AlertButton := SHOW_ALERT(Alert_ID);
      /* Now I can test the value of n_AlertButton for 1 or 2 to find out what button the user selected. */
      IF ( n_AlertButton = 1 ) THEN
         /* Do something, because the user selected 'OK' */
      ELSE
         /* It is assumed at this point that the user selected 'CANCEL' */
         /* Stop processing any further. */
         RAISE form_trigger_error;
      END IF;
    END:Hope this helps.
    Craig...
    -- If my response or the response of another answers your question, please mark the response accordingly. Thanks!

  • "catching" a prompt for user input and answering it through zenity?

    I'm trying to write a script (or multiple scripts) that will allow me to use command-line only applications via user defined actions in my file manager without having to open a terminal. Now I realize this basic functionality is already available, but as it stands I am unable to respond to command-line prompts for user input without opening a terminal. Is it possible to write a shell script that would act as a wrapper and allow me to use zenity (or another popup program) to respond to such queries?
    For example if I used a command-line program that prompted me for a password, could I "catch" that prompt with a shell script and answer it through another program, such as zenity?
    Last edited by falconheart (2011-01-16 22:37:25)

    The easier way to do this is to collect the info with zenity first, then pass it on the command line.  If the program insists on prompting, then you could try feeding it the info with redirection if it accepts it from stdin.  For example
    command < info.txt
    where info.txt is a temp file created by your script which contains whatever you want entered into the prompts.  This will work in some cases.

  • 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...

  • Increasing max # of inputs on prompt for user input

    Hi
    I would like to increase the number of inputs beyond 10 available on the prompt user for input function. At the moment I am using 9 of the 10 available inputs each running a subVI from a case structure. I seem to be limited to 10 inputs using the prompt user for input function so is there another way of prompting the user to select from >10  inputs preferably 20. 
    Thanks for any help
    Chris
    Solved!
    Go to Solution.
    Attachments:
    WASP dialog.vi ‏57 KB

    You can always write you own dialog with as many selections as you like.
    Right-click the express VI and "open front panel" This will convert it to a VI that you can edit in any way you want. save it under a new name.
    You might even want to add some validation code, e.g. to make sure that no more than 2 boxes are checked.
    LabVIEW Champion . Do more with less code and in less time .

  • Prompting for user input in nested select statements

    I recently rewrote a query to use a nested select statement instead of specifying every SELECT field on the GROUP BY line.  Here's the query which works perfectly with hard-coded values of '030', '01/01/11', and '12/31/11'.
    SELECT T0.[CardName] AS Customer, T0.[CardCode] as 'Cust ID', T0.[Phone1] as Phone, T0.[CntctPrsn] as 'Contact Person', T0.[Address], T0.[City], T0.[State1] as State, T0.[ZipCode] as 'Zip Code', T0.[Country],  T1.[TotalSales]
    FROM OCRD T0 
    INNER JOIN
       (SELECT I.[CardCode] AS CardCode, SUM(I.[DocTotal]) AS TotalSales
        FROM OINV I
        WHERE left (I.[CardCode], 3) = '030' AND (I.[DocDate] >= '01/01/11' AND I.[DocDate] <= '12/31/11')
        GROUP BY I.[CardCode]) T1
    ON T0.[CardCode] = T1.[CardCode]
    ORDER BY T0.[CardName]
    When I try to prompt for the left 3 characters of the CardCode (or the dates), ie.
        WHERE left (I.[CardCode], 3) = [%0] AND (I.[DocDate] >= '01/01/11' AND I.[DocDate] <= '12/31/11')
    I get an error "Column 'OCRD.CardName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause".
    It's like putting a user variable in the inner SELECT made it part of the outer SELECT which is exactly what I was trying to avoid by re-writing this query with the inner SELECT.
    Can anyone explain what SQL Server is doing here and how to fix it?

    Thanks Gordon.  That's how I originally wrote the query and it works fine.  But I was disturbed that I had to GROUP BY every field in my SELECT statement when I really only wanted to group by CardCode.  So I did some research and came up with this where the inner select still groups by only CardCode and still takes user input.  I don't really understand why you need the commented SELECT statements in the SET lines, but you do.  Something about using real table fields for variables.
    DECLARE @startDate datetime
    DECLARE @endDate datetime
    DECLARE @rep varchar(10)
    SET @rep /* SELECT T0.[CardCode] FROM ORDR T0 WHERE T0.[CardCode] */ = '[%0]'
    SET @startDate /* SELECT T0.[DocDate] FROM OINV T0 WHERE T0.[DocDate] */ = '[%1]'
    SET @endDate /* SELECT T0.[DocDate] FROM OINV T0 WHERE T0.[DocDate] */ = '[%2]'
    SELECT T0.[CardName] AS Customer, T0.[CardCode] as 'Cust ID', T0.[Phone1] as Phone, T0.[CntctPrsn] as 'Contact Person', T0.[Address], T0.[City], T0.[State1] as State, T0.[ZipCode] as 'Zip Code', T0.[Country],  T1.[TotalSales]
    FROM OCRD T0 
    INNER JOIN
       (SELECT I.[CardCode] AS CardCode, SUM(I.[DocTotal]) AS TotalSales
        FROM OINV I
        WHERE left (I.[CardCode], 3) = @rep AND (I.[DocDate] >= @startDate AND I.[DocDate] <= @endDate)
        GROUP BY I.[CardCode]) T1
    ON T0.[CardCode] = T1.[CardCode]
    ORDER BY T0.[CardName]
    FOR BROWSE

  • How to force sql developer to prompt for user input for every execution ?

    Hi Folks,
    Environment: Oracle 11g (on Windows 7)
    SQL Developer: *3.1.07*
    I am executing a PL/SQL code off Sql Developer. The code uses substitution variables to prompt user for input. However,I am only prompted for the user input for the very first run of the code. For the subsequent executions, the code simply picks up the user input from the very first run. This behavior persists for all subsequent runs of the code.
    I have executed the same piece of code from SQL*PLUS and the behavior seems normal (i.e. I am prompted for fresh input for every execution)
    How can flush out the old user input so I can be prompted for new user input for every run of the code in sql developer?
    Thanks in advance
    rogers42

    Hi Rogers42,
    1/try
    undefine
    undefine fred
    select '&&fred' from dual;
    [run this multiple times]
    [prompts gere]
    old:select '&&fred' from dual
    new:select 'a' from dual
    'A'
    a
    [prompts here]
    old:select '&&fred' from dual
    new:select 'b' from dual
    'B'
    b
    2/try
    exit (requires recent version of sql developer: tools->preferences->Database->worksheet->Re-initialize on script exit command)
    select '&&fred' from dual;
    exit
    run this multiple times
    [prompts here]
    old:select '&&fred' from dual
    new:select 'x' from dual
    'X'
    x
    Commit
    [prompts here]
    old:select '&&fred' from dual
    new:select 'y' from dual
    'Y'
    y
    Commit
    3/use &fred instead of &&fred
    For background see
    http://totierne.blogspot.co.uk/2010/04/substitution-and-bind-variables.html
    -Turloch
    SQLDeveloper team

  • Exe running from java fails to get user input .Help me...

    I have an DOS based exe.It just asks for input for a number from the user and prints the number it gtes.
    When I try to execute this program from Java with the following code
    import java.lang.Runtime;
    import java.lang.Process;
    import java.io.*;
    public class runtimetest     {
         public static void main(String[] args)     throws Exception {
              Runtime rt = Runtime.getRuntime();
              Process p = rt.exec("myExe");
    nothing happens.Thatis It doesnot ask for the input .and I am just unable to know whether its running or not.
    What could be wrong?
    What is the other means to tun the DOS based exe that accepts user inputs , from Java.
    Plz help me as I am in urgent need.
    Aathi

    try this
    Runtime r = Runtime.getRuntime();
              Process p = null;
              try
                   System.out.println("Exe will be called");
                   p = r.exec("cmd.exe /c start c:/ur exe path ");
                   p.waitFor();
              catch (Exception e)
                   e.printStackTrace();
              }

  • 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.

  • Prompt for user inputs

    Hi,
    1) Want to prompt user for username & password
    2) connect to oracle
    3) want to use substring function on username entered by user
    3) user of substring output in procedure
    Performed as shown below but not working,
    PROMPT Enter username and password.
    PROMPT
    user:=&username;
    pass:=&passowrd;
    tns:=&tnsname;
    conn user/pass@tns
    PROMPT
    PROMPT
    set serveroutput on
    DECLARE
    variable1;
    variable2;
    varibale3;
    var:=substring(user,1,4);
    BEGIN
    var.package_name.procedure_name(cur);
    FETCH cur INTO variable1,variable2,varibale3;
    dbms_output.put_line('XYZ');
    END;
    Edited by: user640001 on Feb 28, 2012 11:27 PM

    trying to run as below but getting error for 'var'
    DECLARE
    var varchar2(20):=substr('&un',1,4);
    variable1 varchar2(20);
    cur var.package_name.Cursor;
    BEGIN
    var.package_name.procedure_name(cur);
    FETCH cur INTO variable1;
    dbms_output.put_line(variable1);
    END;
    cur var.package_name.Cursor;
    ERROR at line 16:
    ORA-06550: line 16, column 7:
    PLS-00487: Invalid reference to variable 'VAR'
    ORA-06550: line 16, column 7:

  • Question Pertaining to User Input

    I'm have trouble figuring out how to prompt for user input and then use that user input as part of my code. For instance, I want to declare two variables that will hold complex numbers. Then, I want the user to input two complex numbers. After this, I want to place those two newly inputted into the variables that I created. Then I want to determine which of those two has a greater norm/modulus. Finally, I want to print those results out.
    Here is my code so far:
    Normalizable m1 = new Complex();
    Normalizable m2 = new Complex();
             System.out.println("Enter the real and imaginary parts of a complex number: ");
             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));Please point me in the right direction.

    I was making two points at once - and in doing so I might have made it sound more daunting than it really is.
    The first point was a direct answer to your question: use readLine() to get the user input, String methods to break it up and parseDouble() to obtain numerical values to create your Normalizable/Complex.
    I really don't think there's a more straight foward way of approaching things. Try it and see if you can sucessfully read in a single complex number and display it.
    {noformat}
    Enter the real and imaginary parts of a complex number>12 -5
    You entered 12.000 - 5.000i
    {noformat}You will need the API docs for the relevant classes and have read them. Post what you've come up with for this first part of the problem if you get stuck. (I doubt if anyone here will actually write the code for you, since that would take all the fun out of it.)
    Regarding the second point, you're right: by suggesting an auxillary method to read and parse the input I was adding some complexity. Feel free to ignore that suggestion. Personally I prefer a little complexity if it reduces complicated code to managable pieces. Complications will grow into a tangled mess (and are a place for bugs to live in); complexity can always be dealt with one small well documented chunk at a time.

  • Need help with re-prompting the user for input .

    I am trying to wright a code the re prompts the user for input if they enter anything but an integer but I keep getting a "char cannot be dereferenced" error when I try to compile.
    Here's what I have got:
    import java.util.Scanner; // imports Scanner methods
    public class SandBox
      public static void main(String[] args)
          // re-prompting test
          Scanner in = new Scanner(System.in);
          System.out.println("Please enter an integer: ");
          String i = in.nextLine();
          for(int a=0; a<i.length(); a++)
              if( (i.charAt(a).isDigit()) ) {
                  System.out.println("Thank you!");
                  break;
                } else {
                    System.out.println("Please try again");
                    continue;
          int b = Interger.parseInt(i);
      }// end of class
    }//end of main method
     

    Sorry for double posting but it won't let edit my last post.
    I would prefer to go through it without using try catch because it takes longer though I will use it if I cannot get the other way working. I currently have two versions of the code both using try catch and the other way but both say that they "cannot find symbol" when I try to parse. here are both versions of the code:
    import java.util.Scanner; // imports Scanner methods
    public class SandBox
      public static void main(String[] args)
          // try catch test
          boolean inputIsFaulty = true;
          int inputInt = 0;
          Scanner in = new Scanner(System.in);
          do {
             System.out.println("Please enter an integer: ");
             String i = in.nextLine();
             for(int a=0; a<i.length(); a++)
                if (Character.isDigit(i.charAt(a))) {
                  System.out.println("Thank you!");
                  inputIsFaulty = false;
                } else {
                    System.out.println("Please try again");
            while (inputIsFaulty);
          inputInt = Integer.parseInt(i);
      }//end of class
    }//end of main method
    import java.util.Scanner; // imports Scanner methods
    public class SandBox2
      public static void main(String[] args)
          // try catch test
          boolean inputNotOK = true;
          int inputInt = 0;
          Scanner in = new Scanner(System.in);
          do {
             System.out.print("Please enter an integer: ");
             String inputStr = in.nextLine();
             try {
                inputInt = Integer.parseInt(inputStr);
                // this line is only reached if the parse works
                inputNotOK = false;
             catch (NumberFormatException e) {
                System.out.println("You didn't enter a proper number.  Please Try again.");
          while (inputNotOK);
          inputInt = Integer.parseInt(imputStr);
      }//end of class
    }//end of main method
     

  • How can I have a program prompt a user to input a selected number of simultaneous (different devices run off com/rs232 ports) and be able to compile all the data and/or graph it simultaneously?

    I have a project that I'm working on that I could use some help on.
    Some background on it is I'm taking data from a balance via RS-232 (can be a selectable list of balances), and then communicating with them on their own separate COM port. I need these to then run in parallel to then take masses in regular increments and then output them to a graph and/or TDMS file. 
    What I'm trying to have is that a subVI prompts the user to how many simultaneous runs will be going.
    Then I will want multiple pop prompts (one for each simultaneous run) which will have initial data input (data cluster) and then associate these with the COM port and the specified balance. 
    I initially thought of utilizing a For Loop this way but I can't get these windows to pop up multiple times while storing their own values in say a cluster array. Can anyone give me any ideas to get me a little further?

    Cameron,
    I've created a prompt for the user to select the number or runs to be run simultaneously. 
    This then should trigger the amount of prompts the user needs to input - ie VISA resource, and headers to label the "samples".
    I want this to be done in multiples (somewhere around 1-10 simultaneous runs - bounded by the program) so that data points from multiple sources can be taken and graphed/saved to file. I just am having issues with the loop situation to be able to keep prompting the user X times and also output the data to the front panel. Originally i thought I could somehow manipulate a tab control container but I'm getting roadblocked. 
    Does that help you understand what I'm trying to do?
    I've attached an image of what I want the user to input for each sampling.
    Attachments:
    Capture11.JPG ‏24 KB

  • User input prompt in CASE statement

    I would like to obtain user input via a prompt and use what the user selects in my OBIEE Report case statement.
    For example &START_DATE AND &END_DATE are user inputs:
    CASE when SHIP_DATE BETWEEN &START_DATE AND &END_DATE THEN 1
    Thanks

    Use presentation variables for start and end_dates
    In the criteria tab->SHIP_DATE->click on fx
    on Edit Column Formula->Bin Tab->
    Add Bin->Add button->Variable->Presentation
    Use the presenation variables with with required condition
    Okay then set 1 at Edit Bin Name
    Mark if helps
    Srini VEERAVALLI on Feb 7, 2013 5:23 PM
    Any updates on this?
    Edited by: Srini VEERAVALLI on Feb 20, 2013 4:10 PM

  • How to change date format of user input prompt in infoview.

    Hi All,
    Every report webi or deski having date field as prompt when viewed in view mode in infoview shows date format as M/d/yyyy h:mm:ss a.
    Where this format is stored and how can we change it to dd/mm/yyyy.
    Any ideas.
    Regards,
    Gaurav

    Not sure id this helps...
    I was up against a similar issue of placing the user input dates, Starting & Ending, into one cell for a reference on each report header. After a few hours of diligence, I came up with a working model that finally worked:
    u_StartDateAsTXT=FormatDate(ToDate(UserResponse("Enter Date/Time Shipped (Start):");"MM/dd/yyyy hh:mm:ss a");"MM/dd/yyyy")
    and
    u_EndDateAsTXT=FormatDate(ToDate(UserResponse("Enter Date/Time Shipped (END):");"MM/dd/yyyy hh:mm:ss a");"MM/dd/yyyy")
    The report header has the following function:
    =u_StartDateAsTXT + u201C u2013 u201C + u_EndDateAsTXT

Maybe you are looking for

  • Z report for opening qty of material date wise

    I have to develop a zreport which will calculate date wise opening  stock of material   and closing stock of that material at particular location ( not to use standard reports) I have to display sale qty and stock transfer qty  date wise. Similarly r

  • IPhoto pictures as file attachments in email

    Does anyone know how to attach picture files from iPhoto in an email. No matter what I try, the picture gets imbedded in the email instead of as a file attachment. I am new to Apple and Mac having done Windows all my life. Thank you.

  • Using a Search Window to Filter Data In PowerPivot on Sharepoint?

    When viewing a PowerPivot workbook natively all is well. However when I save it to Sharepoint and view it via a browser, I find that the option to filter data by typing in a value is no longer present. (All there is is an extremely LONG list of value

  • Why after trying to install it is saying an error occured while installation

    and it takes me straight to the finish button

  • 10.4.7 and now bad bluetooth

    I have a G4 cube (look at my profile) with a D Link bluetooth adapter for my apple bluetooth mouse and keyboard. After installing the 10.4.7 Power PC update, I forgot to turn on my keyboard at the restart, so the setup assistant came up and asked me