Oracle更新操作筆記以及語句

字號(hào):


    這幾天都在學(xué)學(xué)習(xí)數(shù)據(jù)庫(kù)Oracle,之前寫了一個(gè)Oracle查詢語句的筆記,現(xiàn)在給大家公布下更新操作的筆記,其中包事務(wù)的處理。
    *數(shù)據(jù)庫(kù)更新操作數(shù)據(jù)庫(kù)主要操作分為兩種
    ·數(shù)據(jù)庫(kù)查詢操作:select
    ·數(shù)據(jù)庫(kù)更新操作:insert(增加)、update(修改、更新)、delete(刪除)
    復(fù)制一張表 create table myemp as select * from emp;(復(fù)制了emp表)
    ·insert 添加數(shù)據(jù)語法
    標(biāo)準(zhǔn)格式:
    _____________________范例________________________________
    insert into myemp( EMPNO,ENAME, JOB,MGR, HIREDATE, SAL, COMM, DEPTNO)
    values(7899,'張三','清潔工',7369,'02-4月 -81',9000,300,40);
    ___________________________________________________________________
    簡(jiǎn)略寫法:因?yàn)橐砑铀凶侄蔚牡闹?,就不用寫出字段的名稱,只要字段的順序和表的順序一致就行
    _____________________范例___________________________________________________
    insert into myemp values(7899,'張三','清潔工',7369,'02-4月 -81',9000,300,40);
    ____________________________________________________________________________
    to_date函數(shù),把一個(gè)字符串轉(zhuǎn)換成DATE型數(shù)據(jù)to_date('2001-01-09','yyyy-mm-dd')
    ·update 更新語句 可加where條件 表示修改條件(修改局部)
    _______________________范例___________________
    update myemp set comm=1000;(所有獎(jiǎng)金修改1000
    )
    update myemp set comm=5000 where empno=7899;(7899編號(hào)的人修改獎(jiǎng)金5000)
    ______________________________________________
    ·delete刪除語句
    delete from 表名稱 刪除表。 完整刪除
    delete from 表名稱 where 條件; 局部刪除
    刪除表,delete from myemp;##############事物的處理###########
    ·事物處理就是保證數(shù)據(jù)操作的完整性,所有的操作要么同時(shí)成功,要么同時(shí)失敗。
    其實(shí)就是說一個(gè)用戶對(duì)表進(jìn)行 *增 *刪 *改 的時(shí)候,會(huì)建立以一個(gè)session(會(huì)話)
    1.提交事物:commit; 確定操作正確。 提交之后就不能回滾
    2.回滾操作:rollback; 回滾之前操作。
    *!死鎖!*
    一個(gè)session更新了數(shù)據(jù)庫(kù)記錄,其他session是不法立刻更新的,要等待對(duì)方提交之后才能更新
    --conn scott/tiger@orcl_localhost;
    --create table myemp as select * from emp;
    --select * from myemp;
    /*
    insert into myemp( EMPNO,ENAME, JOB,MGR, HIREDATE, SAL, COMM, DEPTNO)
    values(7899,'張三','清潔工',7369,'02-4月 -81',9000,300,40);
    */
    /*
    insert into myemp
    values(7899,'李四','送水',7369,'02-4月 -81',9000,300,40);
    insert into myemp values (7983,'王五','清潔工',null,'02-4月 -81',8000,null,40);
    insert into myemp
    values(7899,'李九','保潔',7369,to_date('2001-01-09','yyyy-mm-dd'),9000,300,40);
    select * from myemp;
    */
    --update myemp set comm=1000;
    --update myemp set comm=5000 where empno=7899;
    --update myemp set mgr =null ,comm=null where empno in(7899,7983,7899);
    select * from myemp;
    delete from myemp where empno=7899;
    select * from myemp;
    ##############事物的處理###########
    --create table emp10 as select * from emp where deptno=10;
    --select * from emp10 where deptno =10;
    --delete from emp10 where empno=7782;
    --select * from emp10;