Statements in Oracle TCL
Statements in Oracle TCL is one of the most important part in the subset of Oracle statements. TCL means Transaction Control Language.
There is more chance that there will be a interview questions in this section.
Before reading this article one should know more differences between DDL and DML commands which are already posted before.
What is mean by Transaction ?
Transaction means an event that takes place between two commit points, For example: In Retail words, the transaction means buying and selling any goods so that complete event is called as transaction.
What is mean by Failed Transaction ?
Failed Transaction means thus that event is failed to achieve the commit point after the event starts. For example: If you sending any amount in online transaction means due to some technical issues there will be failed to achieve the commit points in other side so that event is called as failed transaction.
This TCL is mainly related to the above two questions only.
List of Statements in Oracle TCL
The List of Transaction Control Language statements in oracle are:
- COMMIT
- ROLLBACK
- SAVE POINT
Importance of Commit in TCL
- Commit is used to end the transaction and save the changes whatever we done that which are done in the previously in that same session.
- If you failed to give commit means the changes will not be happened in same scenario.
When this Commit is required ?
Commit Statement is required whenever we are using any DCL (Data Control language) means we will use Commit statement, because they are manual commit statement.
Whereas DDL (Data Definition Language) is auto commit statement so it doesn't required any commit statements to this scenario.
Let's take two different session,
SESSION 1 :
CREATE TABLE trans (id NUMBER );
DDL is auto commit statement so no need to give commit, while using other session.
SESSION 2:
Here both session 1 and session 2 are showing the DDL part, they are auto commit statement, so it will automatically ends the transaction in data base itself.
Two Different Session Using DML statements
SESSION 1: => NO COMMIT
In figure, we have inserted 3 records, which is DML operations are performed so, if we failed to give commit means it will rollback, while viewing in another session.
SESSION 2:
AFTER COMMITING in SESSION 1:
Now SESSION 2 can able to view the records which was created in session 1.
TRY IT BY YOURSELF
- Create a table oracle with columns as item NUMBER
- Now Insert three records 1, 2, 3
- DELETE record 3
- Now Insert two records 4, 5
- Rename the column from item to new_item
- Now Insert two records 6 and 7
- Delete record 7
Now find how many records are in another session, check it.... ?????
Important Note
In some cases other than commit we can end the transaction by using this keywords like,
- Commit
- Exit
- Using DDL command
In PLSQL block this is very important point, whenever you are using any DML statements means, commit is required one.
ROLLBACK
Rollback is very similar to undo like process, while we are doing any DML operations means, at the time if we need to do undo means, just use this rollback command to go to the implicit save point.
During this situation there should not be use any commit or DDL operations else it wont rollback. If it is once roll backed means it can't be redo.SAVE POINT
Save point is used to rollback the particular transaction where the save point are available. For Example: INSERT INTO trans VALUES (8); INSERT INTO trans VALUES (9);
SAVEPOINT S1;
INSERT INTO trans VALUES (10);
INSERT INTO trans VALUES (11);
SAVEPOINT S2;
SERT INTO trans VALUES (12);
INSERT INTO trans VALUES (13);
SAVEPOINT S3;
DELETE FROM trans
WHERE id = 10;
SAVEPOINT S4;
INSERT INTO trans VALUES (20);
SAVEPOINT S5;
Now,
ROLLBACK to S2;
Points to remember:
- Whenever you are using any DML operations means it will be very important to commit the transaction.
Conclusion
I hope you have understand, and got some ideas related to the article, so if you having any doubts or queries means kindly comment below or reach out to our official mail id.
Interview Questions
1, Can we use TCL in trigger (PLSQL) ?
2, What happens when the transaction is not committed means ?
3, What is Transaction ?
4, What is Save point ?
5, What is Rollback ?
6, Difference between Roll back and Rollback 2 ?
Comments
Post a Comment
Thanks for commenting, we will always respond your comment.