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
Similar Messages
-
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 -
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 -
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 -
How to control user input with a button?
How do I control a user input from a dialog box by activating it with a button. I am saying "press zero", then when the user does press zero, it should zero the scale.
The user has only one button they can press. You should enable the cancel so that the dialog can output an F.
What you have works, but the zero will not occur until the case is activated. If the insides of the case do not work, that is another story. Put a pop up in the active case to convince yourself that the case is being entered.
This, what you have, always returns T.
Mark Ramsdale -
Hello all!
I'm kinda new to Java and especially to these forums. I know it's impolite to go into a community and ask for something straight away; but I really can't find a solution to my problem:
I'm trying to make a small hangman game with console user input. The code:
package mystupidjavaapp;
import java.util.*;
import java.awt.*;
public class MyStupidJavaApp
public static void main(String[] args)
Scanner console = new Scanner (System.in);
System.out.println("Let's play hangman are you ready? ");
String s = console.nextLine();
DrawingPanel panel = new DrawingPanel(500, 400);
Graphics g = panel.getGraphics();
panel.setBackground(Color.white);
drawingPanel(g);
userInput(console, g, s);
public static void drawingPanel( Graphics g)
g.setColor(Color.black);
g.drawLine(50, 50, 50, 70);
g.drawLine(50, 50, 100, 50);
g.drawLine(100, 50, 100, 150);
g.drawLine(75, 150, 125, 150);
g.drawString("Hello and welcome to a small sample of a hangman game!", 120, 50);
public static void userInput(Scanner console, Graphics g, String s)
int roll=0;
String word = "";
while (!s.equals("yes"))
console.next();
System.out.println("Well if you can't say a simple \"yes\" then we can't go on. ");
s = console.nextLine();
System.out.println("Nice! ");
Random r = new Random();
roll = r.nextInt(4)+1;
if (roll == 1)
word = "pu";
else if (roll == 2)
word = "copac";
else if (roll == 3)
word = "bani";
else
word = "casa";
if (roll !=0)
g.drawLine(150, 130, 200, 130);
for (int i=0; i<=word.length()-1; i++)
g.drawLine(150+i*70, 130, 200+i*70, 130);
int tries=0, position=0, guess=0;
while (tries <= 6 && guess<=word.length())
System.out.println("Ok please input a letter(one letter at a time please): ");
String s1 = console.next();
char c = s1.charAt(0);
for (int i=0; i<word.length(); i++)
if (word.charAt(i) == c)
position = i;
System.out.println("Congratulations you got a letter right! ");
guess++;
if (position==1)
{g.setFont(new Font("SansSerif", Font.PLAIN, 40));
g.drawString(s1.substring(0,1), 170, 125);}
else if (position!=0)
{g.setFont(new Font("SansSerif", Font.PLAIN, 40));
g.drawString(s1.substring(0,1), 170+70*position, 125);}
else
tries++;
}My main problem is with the "while (!s.equals("yes"))" part, where if I enter the loop it will never exit it. What to do? Also, I tried watching for variables but I dunno how to do that to be honest :(. (In Netbeans, I tried going in the top "Debug" menu and there I selected "New Watch" and I chose the variable I wanted. Sadly as I run my code, in the watch window my variable is unchanged; moreover it doesn't even receive a value)
Suggestions/ help anyone :S?Hello!
Thanks for the reply and sorry for my late reply. I wanted to start out by watching the "tries" variable but I have no idea what I'm doing. i tried setting break points throughout my code but nothing seems to happen/change. I need a step by step tutorial on how to watch a variable "evolve" through my code. I know this is probably a nuisance but until I find a good tutorial on it, I dunno how to do it :(.
**QUICK EDIT**
I finally got it to work! The main problem started because I couldn't get all the letters to show up on the right spot or sometimes I couldn't get the letters to show up at all. But after staring at the code for awhile I decide to ditch the "if" that was generating the letters. Here's how it looks now and it works flawlessly! (In case some1 is curious.)
package mystupidjavaapp;
import java.util.*;
import java.awt.*;
public class MyStupidJavaApp
public static void main(String[] args)
Scanner console = new Scanner (System.in);
System.out.println("Let's play hangman are you ready? ");
String s = console.nextLine();
DrawingPanel panel = new DrawingPanel(500, 400);
Graphics g = panel.getGraphics();
panel.setBackground(Color.white);
drawingPanel(g);
userInput(console, g, s);
public static void drawingPanel( Graphics g)
g.setColor(Color.black);
g.drawLine(50, 50, 50, 70);
g.drawLine(50, 50, 100, 50);
g.drawLine(100, 50, 100, 150);
g.drawLine(75, 150, 125, 150);
g.drawString("Hello and welcome to a small sample of a hangman game!", 120, 50);
public static void userInput(Scanner console, Graphics g, String s)
int roll=0;
String word = "";
while (!s.equals("yes"))
console.next();
System.out.println("Well if you can't say a simple \"yes\" then we can't go on. ");
s = console.nextLine();
System.out.println("Nice! ");
Random r = new Random();
roll = r.nextInt(4)+1;
if (roll == 1)
word = "pu";
else if (roll == 2)
word = "copac";
else if (roll == 3)
word = "bani";
else
word = "casa";
g.drawLine(150, 130, 200, 130);
for (int i=0; i<=word.length()-1; i++)
g.drawLine(150+i*70, 130, 200+i*70, 130);
int tries=0, position=0, guess=0;
while (tries <= 6 && guess<=word.length())
System.out.println("Ok please input a letter(one letter at a time please): ");
String s1 = console.next();
char c = s1.charAt(0);
for (int i=0; i<word.length(); i++)
if (word.charAt(i) == c)
position = i;
System.out.println("Congratulations you got a letter right! ");
guess++;
g.setFont(new Font("SansSerif", Font.PLAIN, 40));
g.drawString(s1.substring(0,1), 170+70*position, 125);
else
tries++;
if (tries == 1)
g.drawOval(40, 70, 30, 30);
else if (tries == 2)
g.drawLine(50, 100, 50, 140);
else if (tries == 3)
g.drawLine(50, 110, 20, 120);
else if (tries == 4)
g.drawLine(50, 110, 80, 120);
else if (tries == 5)
g.drawLine(50, 130, 20, 140);
else if (tries == 6)
g.drawLine(50, 130, 80, 140);
}Sadly I couldn't manage to understand how to use breakpoints :|.
Edited by: 890334 on Jan 23, 2012 1:53 PM -
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 AMHi 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. -
Proxy User Authentication with SQL Developer
Hello,
I realized that there are 2 methods for configuring SQL Developer to user Proxy User Authentication.
1) one-session method with Syntax:
personaluser[appuser]
2) two session-method with dialog "Proxy Connection"
For me it is unclear, why anybody would want to use the two-session-method.
a. you need username/password for both user acocunts (personaluser and appuser)
b. it is unclear which operations in SQL Developer are using the personaluser account. It seems that the SQL Window is only using appuser account.
What was the motivation to implement Two Session Method?
Best regards,
MartinI found the possibility that proxy authentication of both accounts can be enforced:
SQL> alter user appuser grant connect through personaluser AUTHENTICATION REQUIRED;
I guess that this is the motivation for implementing the 2-session proxy connection method in SQL Developer.
Regards,
Martin -
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.
-
Can't take User input with DataInputStream!!!
public class DataInputStrm
public static void main( String[] args ) {
DataInputStream dIpStream = new DataInputStream( System.in );
try {
System.out.println( "Enter an integer" );
int anInteger = dIpStream.readInt();
// does not work
System.out.println( "You have entered " + anInteger );
catch( java.io.IOException e ) {
e.printStackTrace();
} // end of main
} // end of class DataInputStrm/** Problems:
1. If an one digit integer is entered( 2, 3 etc ), it is waiting for another!
Does not happen for an integer with more than one digit.
2. Displays garbage when the integer value is output.
Please help immediately!DataInputStream/DataOutputStream provide a way of reading and
writing complex objects in a way that works on all sorts of different
computers.
What you probably want is a Scanner. These things are designed
to read relatively simple data only (numbers, strings, lines, boolean
values etc) from just about any source (anything Readable).
Here's your example, but using a Scanner:import java.util.Scanner;
public class ScanEg
public static void main( String[] args ) {
Scanner in = new Scanner(System.in);
System.out.println( "Enter an integer" );
int anInteger = in.nextInt();
// but what if it's not an integer...
System.out.println( "You have entered " + anInteger );
}Works fine, but you might want to consult the documentation to
find out what happens if the user doesn't enter a number, or if
there's an i/o error. The API documentation is here:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html
Scanner is discussed in the tutorial here:
http://java.sun.com/docs/books/tutorial/essential/io/scanning.html -
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. -
Validate user input with the screen flow logic.
Hello guys, im facing some troubles with the following code
field mara-matnr SELECT *
from mara
into table itab_mara
where matnr = mara-matnr
and matnr = mara-matkl
WHENEVER NOT FOUND SEND ERRORMESSAGE 107
WITH mara-matnr .
the editor doest recognize this code in PAI., is the same with VALUES clause.
what im doing wrong ? . thank you very mch.Hi,
Please check code in where condition. Is the condition is right?
field mara-matnr SELECT *
from mara
into table itab_mara
where matnr = mara-matnr
and matnr = mara-matkl
WHENEVER NOT FOUND SEND ERRORMESSAGE 107
WITH mara-matnr .
MATNR is comparing with MATNR and also MATKL.
When you are doing the valiation make sure that use the chain and endchain stamt.
PAI
CHAIN:
MODULE VALI_DATA.
END CHAIN.
Like above do the code. -
Count the number of columns return in an user-input sql query
I need to do something like this
I let an user input a sql query and then execute it
assuming the sql query is always correct, it will return a Resultset
then a table will pop up to accomodate the number of columns the resultset will produce
i'm stuck at the part on how to check how many columns of data will be return in the resultsetResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount(); -
User input in flash with aspx server
Hi so far I've created a flash file with user input with
fields such as name and email. But now I need to find a way to
script the input fields so that it would send those inputted
information to an aspx.net server, and also respond to the user's
input by saying "thank you" when the message is correctly sent.
Please help me out, I am new to aspx.net and also new to how
flash connects to server with action script coding. PLEASSSeEE
helppppDoes the programmer want XML or URL Variables?
For URL variables follow the example for
LoadVars.sendAndLoad
for XML follow the example for
XML.sendAndLoad -
Cannot Read user input on Adobe Form .
Hi team,
Can you please go through the issue -
Developed Interactive Adobe form. Called by webdynpro application.
Interactive properties enable, display type - native, with pdfsource, template source and data source cleanly populated.
Submit button is webdynpro native with option CLICK and corresponding code selected in ADOBE FORM.
All the elements in adobe forms cleanly binded and checked more than 10 times to avoid any mistakes or wrong bindings.
Event handler code is written for submit button to read the data eneted by user on adobe form.
lo_el_zleaver_form->get_static_attributes(
IMPORTING
static_attributes = ls_zleaver_form ).
User is able to enter data on adobe form and control is comming to Submit button code but i am not able to read the user input with above code.
BASIS has check and confirmed that license is installed properly. I am using adobe reader 9 and adobe designer 8.2 and will ECC version 6.0 . Basis has confirmed the ADS configuration, Java stack and ABAP stack are compatible.
We are using the ADS from SAP NetWeaver 7.01 (EhP1, Java Stack) in
combination with SAP NetWeaver 7.00 SP15 (ABAP stack).
Mohan.Hi Guys,
I also created one more Adobe interactive form to test and again USER INPUT CANNOT BE READ. After user click on SUBMIT button the below code is written in SUBMIT button. I am not able to read department details below enteted by user. Is there any othe method you want me to call. I also tried GET_ATTRIBUTE
Will there be any problem with above version of ADS or ALD etc..
DATA lo_nd_zdept TYPE REF TO if_wd_context_node.
DATA lo_el_zdept TYPE REF TO if_wd_context_element.
DATA ls_zdept TYPE wd_this->element_zdept.
navigate from <CONTEXT> to <ZDEPT> via lead selection
lo_nd_zdept = wd_context->path_get_node( path = `ADOBE.ZDEPT` ).
@TODO handle non existant child
IF lo_nd_zdept IS INITIAL.
ENDIF.
get element via lead selection
lo_el_zdept = lo_nd_zdept->get_element( ).
@TODO handle not set lead selection
IF lo_el_zdept IS INITIAL.
ENDIF.
get all declared attributes
lo_el_zdept->get_static_attributes(
IMPORTING
static_attributes = ls_zdept ).
This is other interactive form where i also tried GET_ATTRIBUTE
USING GET_ATTRIBUTE***************
node_info = lo_nd_zleaver_form->get_node_info( ).
I tried both GET_ATTRIBUTE and GET_ATTRIBUTES but failed.
node_info->GET_ATTRIBUTES(
RECEIVING
ATTRIBUTES = stru_zleaver_Forms ) .
OR
lo_nd_zleaver_form = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_ZLEAVER_FORM ).
lo_EL_zleaver_form->GET_ATTRIBUTE( EXPORTING NAME = 'LEAVES_TAKEN'
IMPORTING VALUE = LW_LEAVES_TAKEN ).
Maybe you are looking for
-
I am working on separating a face from its backgound. My problem is that I can't figure out how to include the bit of background that shows up inside the lens of his glasses. With the narrow frames, I'm stumped on how to do it. BTW, the background wa
-
How do i stop my iphone from automatically transferring purchases from iphone to computer?
I purchase songs and convert them to mp3 and then delete AAC files so as to not have duplicates which I've done for years since the new update the iphone automatically transfers all the AAC files from the iphone thus creating duplicates I have tried
-
Query diferent output between 11gR1 and 11gR2
We have a complex query which has been working fine in 11gR1 and after changing aplication to 11gR2 it started generating an error. This simple table and query shows the same error I am seeing. In 11gR2 this first select gives an error ORA-00979 In 1
-
Can't see local computers in network neighborhood anymore
Hello, I bought a WRT610N on Friday to replace my WRT54G and while it is running great I have a small issue. If I go to browse my local network, I don't see a list of computers like I used to with the WRT54G If I type \\computername then I can access
-
Hey guys, I really love Safari, and I feel it is a superior browser to Firefox (the other browser I use daily), but for it to become my main browser, I would really like to have favicons show up in the bookmark bar, instead of just text. I'm sure you