PL/SQL SELECT INTO Existing Table

The SELECT INTO statement is one of the most frequently used statements in PL/SQL. With the SELECT INTO statement in PL/SQL, you can fetch records from the database and bind them to those variables.

The SELECT INTO statement for the database the most plays the role of both fetching data from the database into the code and substituting variables with the data into the PL/SQL code. It puts the result of a query question to a variable or a variety of variables. These parameters should correspond to the datatypes of the columns used in the query, if they are not, an error may arise.

Syntax:

SELECT column1, column2, . . . . , column_n

INTO

variable1, variable2, . . . . , variable_n

FROM table

WHERE expresion1, expression2, . . . . , expression_n;

Explanation: In the above syntax, we are first selecting the column from which value is to be fetched using the SELECT keyword, and then by using the WHERE clause we are getting that particular data and then we are copying that particular data into the variable using INTO keyword.

PL/SQL SELECT INTO Existing Table

PL/SQL is a programming language that is used alongside SQL for writing procedural code such as stored procedures, functions, triggers, and packages within the Oracle Database. It was developed by Oracle Corporation and is widely used in database programming.

PL/SQL is a programming language that has three parts: the Declarative part, the Executable part, and the Exception-handling part. PL/SQL blocks are created using four keywords: DECLARE, BEGIN, EXCEPTION, and END. In the DECLARE part, we declare constants and variables. In the BEGIN block, we write the instructions that need to be executed. In the EXCEPTION part, we handle any exceptions that might occur. Finally, the END keyword indicates the end of the PL/SQL statements. In this article, you will learn about how to use a SELECT INTO statement in an existing table in PL/SQL, its functionality along with some examples.

Similar Reads

PL/SQL SELECT INTO Existing Table

The SELECT INTO statement is one of the most frequently used statements in PL/SQL. With the SELECT INTO statement in PL/SQL, you can fetch records from the database and bind them to those variables....

Example of PL/SQL SELECT INTO Existing Table

Let’s take an example of EMPLOYEE table having EMP_ID, NAME, AGE, and SALARY as columns....

Conclusion

In Conclusion, the declaration SELECT INTO statement in PL/SQL is a very effective method to pull the data from the database and assign that data to the variables working with PL/SQL code. One of its major functions is to offer a time-efficient selection of one or more rows and increase the flexibility of data manipulation and handling. It is necessary, however, to remind yourself that SELECT INTO should be used mainly for retrieving data into variables, but not for inserting data into existing tables. The feature, therefore, speeds up subsets of data collection within PL/SQL programs, letting the developers simply work with the table data for a host of purposes like calculations, validations, and business logic implementation....