![]() |
PL/SQL is a powerful extension of SQL specifically designed for Oracle databases. It enables developers to create procedural logic and execute SQL commands within Oracle database environments. In this article, we will explore the usage of fundamental PL/SQL statements such as INSERT, UPDATE, DELETE and SELECT with he help of various examples which are essential for manipulating data in Oracle databases. Set Up an EnvironmentTo understand How To Use PL SQL Insert, Update, Delete, And Select Statement we need a table on which we will perform various operations and queries. Here we will consider a table called students as shown below: CREATE TABLE students ( 1. Using INSERT StatementINSERT statement in the PL/SQL is used to add the new records or rows of data into the table. It allows u to specify the table name, columns where the data will be inserted and the corresponding values to be inserted into the columns. Syntax for INSERT Statement: INSERT INTO table_name (column1, column2, ...) Explanation:
Examples of INSERT StatementExample 1: Let’ insert some data into the students table. INSERT INTO students (student_id, first_name, last_name) Output:
Explanation:
Example 2: INSERT INTO students (student_id, first_name, last_name) Output:
Explanation:
2. Using UPDATE StatementUPDATE statement in the PL/SQL is used to the modify the existing records in table. It is allowed us to specify the table name, columns to updated new values for these columns and an optional conditional to the filter which rows are to be updated. Syntax for UPDATE Statement: UPDATE table_name Explanation:
Examples on UPDATE StatementExample 1: Let’s update the last name of the students as Anderson whose student_id is 3. UPDATE students Output:
Explanation:
Example 2: Let’s update the first name of the students as Mitch whose student_id is 3. UPDATE students Output:
Explanation of the Code:
3. Using DELETE StatementDELETE statement in the PL/SQL is used to remove the one or more records from the table. It is allowed you to the specify the table name and optional condition to the filter which rows are to be deleted. Syntax for DELETE Statement: DELETE FROM table_name Explanation:
Examples on DELETE StatementExample 1: Let’s delete the student from the table whose student_id is 4. DELETE FROM students Output:
Explanation of the Code:
Example 2: Let’s delete the student from the table whose student_id is 2. DELETE FROM students Output:
Explanation of the Code:
4. Using SELECT StatementSELECT statement in the PL/SQL is used to the retrieve the data from one or more tables. It is allowed you to the specify the columns you want to be retrieve, table from the which you want to be retrieve the data and optional condition to filter rows retrieved. Syntax for SELECT Statement: SELECT column1, column2, ... Explanation:
Example on SELECT statementsSELECT student_id, first_name Explanation:
Output:
Explanation: After executing the SELECT statement, the above output shows the student_id and first_name columns from the students table. ConclusionOverall, We have learned the essential concepts and syntax for the using PL/SQL INSERT, UPDATE, DELETE and SELECT statements in Oracle databases. By the understanding of the fundamentals of SQL operations, you can be effectively manipulate and query the data within the Oracle databases using the PL/SQL. Whether you are adding the new data, updating the existing records, deleting the unwanted entries or retrieving the information these statements provide the necessary tools for the managing the database content. |
Reffered: https://www.geeksforgeeks.org
Databases |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |