今天在Oracle的SQL plus 中執行了刪除和查詢操作,然後在PL/SQL中也執行查詢操作,語句一樣,結果卻不一樣,讓我大感鬱悶,後來才突然想到可能是兩邊資料不一致造成的,但是為什麼不一致呢,就是沒用commit,
在網上查了一下,大概是這樣說的:
DML語言,比如update,delete,insert等修改表中資料的需要commit;
DDL語言,比如create,drop等改變表結構的,就不需要寫commit(因為內部隱藏了commit);
DDL 資料定義語言 (Data Definition Language):
create table 建立表
alter table 修改表
drop table 刪除表
truncate table 刪除表中所有行
create index 建立索引
drop index 刪除索引
當執行DDL語句時,在每一條語句前後,oracle都將提交當前的事務。如果使用者使用insert命令將記錄插入到資料庫後,執行了一條DDL語句(如create
table),此時來自insert命令的資料將被提交到資料庫。當DDL語句執行完成時,DDL語句會被自動認可,不能復原。
DML 資料操作語言:
insert 將記錄插入到資料庫
update 修改資料庫的記錄
delete 刪除資料庫的記錄
當執行DML命令如果沒有提交,將不會被其他會話看到。除非在DML命令之後執行了DDL命令或DCL命令,或使用者退出會話,或終止執行個體,此時系統會自動
發出commit命令,使未提交的DML命令提交。
DDL :
Data Definition Language (DDL) statements are used to define the database structure or schema. Some examples:
CREATE - to create objects in the database
ALTER - alters the structure of the database
DROP - delete objects from the database
TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed
COMMENT - add comments to the data dictionary
RENAME - rename an object
DML:
Data Manipulation Language (DML) statements are used for managing data within schema objects. Some examples:
SELECT - retrieve data from the a database
INSERT - insert data into a table
UPDATE - updates existing data within a table
DELETE - deletes all records from a table, the space for the records remain
MERGE - UPSERT operation (insert or update)
CALL - call a PL/SQL or Java subprogram
EXPLAIN PLAN - explain access path to data
LOCK TABLE - control concurrency
DCL
Data Control Language (DCL) statements. Some examples:
GRANT - gives user's access privileges to database
REVOKE - withdraw access privileges given with the GRANT command
TCL
Transaction Control (TCL) statements are used to manage the changes made by DML statements. It allows statements to be grouped together into logical transactions.
COMMIT - save work done
SAVEPOINT - identify a point in a transaction to which you can later roll back
ROLLBACK - restore database to original since the last COMMIT
SET TRANSACTION - Change transaction options like isolation level and what rollback segment to use