How to get user input at runtime

I want to use runtime input from the user in oracle 10g pl / sql blocks (i.e. interactive communication with the user), is this possible?

declare x number; begin x=&x; end 

this code gives an error as it cannot be used in oracle 10g.

+10
oracle oracle10g user-input
source share
7 answers

To read user input and save it in a variable, you can use the sqlplus ACCEPT command for future reference.

 Accept <your variable> <variable type if needed [number|char|date]> prompt 'message' 

example

 accept x number prompt 'Please enter something: ' 

And then you can use the x variable in the PL / SQL block as follows:

 declare a number; begin a := &x; end; / 

Work with a sting example:

 accept x char prompt 'Please enter something: ' declare a varchar2(10); begin a := '&x'; -- for a substitution variable of char data type end; -- to be treated as a character string it needs / -- to be enclosed with single quotation marks 
+18
source share

This is because you used the following line to assign an invalid value.

 x=&x; 

In PL / SQL, an assignment is performed using the following.

:=

So your code should be like this.

  declare x number; begin x:=&x; -- Below line will output the number you received as an input dbms_output.put_line(x); end; / 
0
source share
 declare a number; b number; begin a:= :a; b:= :b; if a>b then dbms_output.put_line('Large number is '||a); else dbms_output.put_line('Large number is '||b); end if; end; 
0
source share
 'DECLARE c_id customers.id%type := &c_id; c_name customers.name%type; c_add customers.address%type; c_sal customers.salary%type; a integer := &a' 

Here c_id Customers.id% type: = & c_id; the operator enters c_id with the type already defined in the table, and the operator is an integer: = & the just entered integer in the variable a.

0
source share

You can try this too and this will work:

 DECLARE a NUMBER; b NUMBER; BEGIN a :=: a; --this will take input from user b :=: b; DBMS_OUTPUT.PUT_LINE('a = '|| a); DBMS_OUTPUT.PUT_LINE('b = '|| b); END; 
0
source share

TRY IT

 declare a number; begin a := :a; dbms_output.put_line('Inputed Number is >> '|| a); end; / OR declare a number; begin a := :x; dbms_output.put_line('Inputed Number is >> '|| a); end; / 
-4
source share

its very simple

just write:

// first create a table called test ....

 create table test (name varchar2(10),age number(5)); 

// when you run the above code, a table will be created ....

// now we have to insert the name and age.

Make sure that age is inserted through the opening of the form, which is looking for our help, to enter a value in it

 insert into test values('Deepak', :age); 

// now run the above code and you will get "1 line inserted" output ...

/ now run the select query to see the output

 select * from test; 

// that's all .. Now I think that no one has any questions left after accepting user data ...

-7
source share

All Articles