PL/SQL and sqlplus query results are different-don't forget commit!

Source: Internet
Author: User
Tags sqlplus



The same SQL statement, the query results in Plsql and Sqlplus are different, have you seen it?


A query was executed today in Plsql's SQL window for select * from T_user; Query to 6 records:



Later, in order to facilitate the testing of other data, opened the Sqlplus, executed the same query statement, accidentally occurred:



query only one record, you are not wrong, the same user, the same SQL statement, the same time, in PL/SQL and sqlplus query results are not the same. So unwilling, ah, opened another N sqlplus window, the execution results are only to query a record. another SQL Window is opened in Ps/sql, and after executing the same SQL statement, it is a record as well as the Sqlplus query result.


In retrospect, most of the problems were in the SQL window that queried the 6 data. at this point, it was found to execute the query select * from T_user; before, there were 5 records inserted:



Originally, unlike the previously used SQL Server and MySQL, when the operation of Oracle, the operation of the data, these operations are only committed to the memory, and did not update the physical files, and finally if the need to update to the physical file, the need to execute a commit command.

At this point, execute the commit command in the SQL window that inserts 5 data, and the data is inserted into the database physical file in a real sense!


So, in Oracle, as long as the database has made changes to the data (increment, delete, change, etc.), it is necessary to execute the commit command to commit the update to the database physical files, otherwise the previous operation is futile.

The comrades who know EntityFramework may have thought of SaveChanges (), yes! The truth is the same as the child drops ~ ~


It is important to note that once a table has been manipulated , the table will be locked and once locked, the other transaction will not be able to manipulate it as follows:


Opens two sqlplus windows, performs the same update operation on the same table, but does not commit.


Execute SELECT * from T_user set user_name= ' UserA ' where user_id= ' user5 ':



Execute SELECT * from T_user set user_name= ' UserB ' where user_id= ' user5 ':



The first operation updated 1 rows, and then the operation was dead, without prompting "1 rows updated".


The reason is that the first operation did not commit, the table T_user has been locked (that is, the legendary lock table ), so before the first action commit, the other transaction is not allowed to operate on this table.

PL/SQL and sqlplus query results are different-don't forget commit!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.