Home » PL/SQL

How to input from user in PL/SQL?

In this article we learn how to take input from user? Just like we use scanf function in C and cin in C++, We will learn how to do the same thing in PL/SQL?
Submitted by Yash Kumar, on October 09, 2017

Here is the syntax of taking input from the user:


Just by writing only this statement we will able to take input from user.

Let's clear this concept by taking an example:

First write the given code in your SQL command prompt

i integer;
j integer;
s integer;
i:=:i;      -----observe this statement. This statement will tell the machine to take input of i through user.
j:=:j;      -----observe this statement. This statement will tell the machine to take input of j through user.
dbms_output.put_line('sum of '||i||' and '||j||' is '||s);     

Note: || operator is used for concatenation of strings.

When you run this code, we will get a new window like this

Take input from use in PL/SQL

Now, fill values like 20 for I and 30 for J and click on submit

How to take input from use in PL/SQL?

We will get the following output:

sum of 20 and 30 is 50

Statement processed.

0.00 seconds

It's definitely easy to understand. Important thing is that the statement i:=:i and the statement j:=:j are used to take input through user as I have already discussed about its syntax <variablename>:=:<variablename>;


Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.