天天看點

Oracle簡單存儲過程示例(持續追加)

[color=red]最後更新日:2014年12月17日[/color]

一些基本操作:

1、修改sys密碼

cmd->sqlplus / as sysdba->alter user sys identified by 新密碼

2、建立使用者

cmd->sqlplus / as sysdba->create user 使用者名 identified by 密碼->

grant connect,resource to 使用者名->conn 使用者名/密碼

3、系統管理者登入

sqlplus / as sysdba

一些注意點:

1、下面兩句等價

--(+)表示該表為從表連接配接至主表,即可以了解為不帶(+)的為基準表

select count(*) from aa09,aa10 where aa09.aaa100 = aa10.aaa100(+)

--left join表示以左表為基準,right join表示以右表為基準

select count(*) from aa09 left join aa10 on aa09.aaa100 = aa10.aaa100

2、Oracle自定義錯誤從-20000開始

3、備份表:create table A1 as select * from personinfo

不要資料隻要表結構可以加上 where 1=2

插入一條資料可以用insert into table select * from othertable

4、取模mod(12,5)

%:表示零個或者多個任意字元

_:代表一個任意字元

<any/all(子查詢)

例:select id from personinfo where id < any (select id from personinfo where id = 25)

分頁:

select * from

(select rownum r,id,personname from personinfo where rownum < 4)

where r > 1

得到日期的指定部分:select extract(year from sysdate) from dual

INTERSECT(交集),傳回兩個查詢共有的記錄

UNION ALL(并集),傳回各個查詢的所有記錄,包括重複記錄

UNION(并集),傳回各個查詢的所有記錄,不包括重複記錄

MINUS(補集),傳回第一個查詢檢索出的記錄減去第二個查詢檢索出的記錄之後剩餘的記錄

PL/SQL塊:

declare

--xxx

begin

--xxx

end;

LOOP循環中可以使用IF結構嵌套EXIT關鍵字退出循環

存儲過程的基本文法:

注意:要得到自增序列,需要先建立一個自增序列,簡單示例如下:

觸發器基本知識:

示例一:

調用:

call PRO_01();
           

示例二:

調用:

示例三:

調用:

call PRO_03(15);
           

示例四:

調用:

示例五:

調用:

示例六:

調用:

示例七:

調用:

select FUN_01('c') from dual;
           

示例八:

調用:

示例九:

調用:

使用中的一些注意點:

1、動态拼接語句執行時,不應該寫成:

而應該寫成:

舉個綜合例子:

建表語句:

存儲過程語句:

另:附件為一些常用的語句和函數