Oracle複習(複習精簡版v1.0)

來源:互聯網
上載者:User

標籤:新手   員工   個數   ffffff   職位   each   fetch   ber   知識   

自己沒記不住的,超基礎Oracle知識,新手可以看一下。

大多數例子是用scott使用者中的emp表完成

 

 

 

排序:order by 列名    desc是降序,預設是升序;

update 表名 set 列名=‘’;

insert into 表名(列名[列名寫全或者不寫全]) values(要與列名對應);

模糊查詢:like“%S%” 含有S ,like“s%”是以S開頭的,like“S_”以S開頭只有兩字母的;

alter table 表名 add constraint 鍵名(列名)

       若是外鍵     鍵名(列名)reference 表名(列);

alter table 表名 drop column 列名;

 

 

序列,常用於插入操作,可以自己增長,在mysql以及sqlserver中可以設定自增長,在Oracle中常用序列

create sequence 序列名

start with 1       從1開始

increment by 1   每次增長1

minvalue 1         最小值是1

nomaxvalue        沒有最大值

cache 10(這裡的cahe是指緩衝10個數);

 

涉及到日期轉換

select to_char(sysdate,“yyyy-mm-dd hh24:mi:ss”)from dual;

查詢部門20中在1981年1月1日之後入職的員工:

select ename from emp where deptno=20 and hiredate > to_date(‘19810101’,‘yyyymmdd’);

 

 

分組

select avg(sal) from  emp表名 grop by deptno列名

選出各個部門,各個職位的平均工資

select deptno,job avg(sal)

from emp

group by deptno,job

order by deptno;

 

 

group by/having/order by以及where的使用順序為

where》group by》having》order by

 

多表串連查詢

查詢和部門10中工作相同的僱員的名字

先查詢部門10中的工作     select distinct【這個用於去重】 job from emp where deptno=10;

則完整句子是  select ename,job from emp where job in【這裡指在後面的範圍之內】( select distinct【這個用於去重】 job from emp where deptno=10)and deptno<>10;

 

 

into關鍵字

select ename,job,into sname,sjob from emp where empno=7396;

 

三種迴圈:

①loop                              ②while i<=100 loop                    ③for i in reverse 1......100 loop 

if i>100 then exit;              s:=s+i;                                       s:=s+i;

end if;                               i:=i+1;                                        end loop;

s:= s+i;                           end loop;

i:=i+1;

end loop;

 

 

執行動態sql語句

daclare

strsql varchar2(100);

begin

strsql:=‘create table ttt(a mumber)’;

excute immediate(strsql);

end;

 

 

遊標

declare 

cursor【遊標關鍵字】 c1 is select empno ,ename,job from emp;

begin

open c1;

fetch c1 into emp.empno,emp.ename,emp.job;

while c1%found loop

dbms_output.put_line();

fetch c1 into emp.empno,emp.ename,emp.job;

end loop;

close c1;

end;

 

 

觸發器

表級觸發器不管一次插入幾行都只執行一次,行級觸發器是插入一行就執行一次

create or replace trigger tri1

before update

on emp

for each row     這句話如果存在就是行級觸發器,如果不存在就是表級觸發器

begin

dbms_output.put_line(‘’);

若想讓其終止運作,在這裡拋出異常 raised ——————————————-;

end;

 

關於old:new

insert:沒有old,有new

update:有old,有new

delete:沒有old,沒有new

 

結束!。。。。

Oracle複習(複習精簡版v1.0)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.