DML Transactions in PLSQL
DML Transactions in PLSQL
Data Insertion
Data Update
Data Deletion
Data Selection
Data Insertion
In PL/SQL, we can insert the data into any table using the SQL
command INSERT INTO. This command will take the table name,
table column and column values as the input and insert the value in
the base table.
The INSERT command can also take the values directly from
another table using 'SELECT' statement rather than giving the
values for each column. Through 'SELECT' statement, we can
insert as many rows as the base table contains.
Syntax:
BEGIN
INSERT INTO <table_name>(<column1 >,<column2>,...<column_n>)
VALUES(<valuel><value2>,...:<value_n>);
END;
The above syntax shows the INSERT INTO command. The table
name and values are a mandatory fields, whereas column
names are not mandatory if the insert statements have values for
all the column of the table.
The keyword 'VALUES' is mandatory if the values are given
separately as shown above.
Syntax:
BEGIN
INSERT INTO <table_name>(<columnl>,<column2>,...,<column_n>)
SELECT <columnl>,<column2>,.. <column_n> FROM <table_name2>;
END;
The above syntax shows the INSERT INTO command that takes
the values directly from the <table_name2> using the SELECT
command.
The keyword 'VALUES' should not be present in this case as the
values are not given separately.
Data Update
Data update simply means an update of the value of any column in
the table. This can be done using 'UPDATE' statement. This
statement takes the table name, column name and value as the input
and updates the data.
Syntax:
BEGIN
UPDATE <table_name>
SET <columnl>=<VALUE1>,<column2>=<value2>,<column_n>=<value_n>
WHERE <condition that uniquely identifies the record that needs to
be update>;
END;
Data Deletion
Data deletion means to delete one full record from the database table.
The 'DELETE' command is used for this purpose.
Syntax:
BEGIN
DELETE
FROM
<table_name>
WHERE <condition that uniquely identifies the record that needs to
be update>;
END;
Data Selection
Data projection/fetching means to retrieve the required data from the
database table. This can be achieved by using the command
'SELECT' with 'INTO' clause. The 'SELECT' command will fetch the
values from the database, and 'INTO' clause will assign these values
to the local variable of the PL/SQL block.
Syntax:
BEGIN
SELECT <columnl>,..<column_n> INTO <vanable 1 >,. .<variable_n>
FROM <table_name>
WHERE <condition to fetch the required records>;
END;