0Day Forums
How to get input from user at runtime - Printable Version

+- 0Day Forums (https://0day.red)
+-- Forum: Coding (https://0day.red/Forum-Coding)
+--- Forum: Database (https://0day.red/Forum-Database)
+---- Forum: Oracle (https://0day.red/Forum-Oracle)
+---- Thread: How to get input from user at runtime (/Thread-How-to-get-input-from-user-at-runtime)

Pages: 1 2


How to get input from user at runtime - porcelainizations555442 - 07-31-2023

I want to take runtime input from user in Oracle 10g PL/SQL blocks (i.e. interactive communication with user). Is it possible?

declare
x number;
begin
x=&x;
end

this code gives error as

> & can't be used in oracle 10g



RE: How to get input from user at runtime - emersonxp - 07-31-2023

its very simple

just write:

//first create table named 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 a name & an age..

Make sure age will be inserted via opening a form that seeks our help to enter the value in it

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

//now run the above code and you'll get
"1 row inserted" output...

/now run the select query to see the output

select * from test;

//that's all
..Now i think no one has any queries left over accepting a user data...



RE: How to get input from user at runtime - mcintire754 - 07-31-2023

TRY THIS


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;
/








RE: How to get input from user at runtime - lollygaggingtrmdsxf - 07-31-2023

That is because you have used following line to assign the value which is wrong.

x=&x;

In PL/SQL assignment is done using 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;
/





RE: How to get input from user at runtime - daisyel - 07-31-2023

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;



RE: How to get input from user at runtime - ciera328 - 07-31-2023

`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;** statement inputs the c_id with type already defined in the table and statement **a integer := &a** just input integer in variable a.


RE: How to get input from user at runtime - pulvereous635221 - 07-31-2023

To read the user input and store it in a variable, for later use, you can use SQL*Plus command `ACCEPT`.


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 a PL/SQL block as follows:

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


Working with a string 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



RE: How to get input from user at runtime - unblamably210170 - 07-31-2023

SQL> DECLARE
2 a integer;
3 b integer;
4 BEGIN
5 a:=&a;
6 b:=&b;
7 dbms_output.put_line('The a value is : ' || a);
8 dbms_output.put_line('The b value is : ' || b);
9 END;
10 /


RE: How to get input from user at runtime - specious329 - 07-31-2023

You can use this to GET and PRINT the prompted value:

set SERVEROUTPUT ON;

/
accept v_x number prompt 'Please enter something: '
declare
v_x NUMBER;
begin
v_x := &v_x;
dbms_output.put_line('the entered value was : ' || v_x);
end;

/


RE: How to get input from user at runtime - wagoning911892 - 07-31-2023

If you are trying to do this in livesql read this .
To my knowledge, this is not possible on livesql. I can't really think of a use case for this, but in any event, you can log feedback in livesql and the team will look at the request.