ORACLE的基本語法集錦
-- 表
create table test (names varchar2(12),
dates date,
num int,
dou double);
-- 檢視
create or replace view vi_test as
select * from test;
-- 同義詞
create or replace synonym aa
for dbusrcard001.aa;
-- 儲存過程
create or replace produce dd(v_id in employee.empoy_id%type)
as
begin
end
dd;
-- 函式
create or replace function ee(v_id in employee%rowtype) return varchar(15)
is
var_test varchar2(15);
begin
return var_test;
exception when others then
end
-- 三種觸發器的定義
create or replace trigger ff
alter delete
on test
for each row
declare
begin
delete from test;
if sql%rowcount < 0 or sql%rowcount is null then
rais_replaction_err(-20004,"錯誤")
end if
end
create or replace trigger gg
alter insert
on test
for each row
declare
begin
if :old.names = :new.names then
raise_replaction_err(-2003,"編碼重複");
end if
end
create or replace trigger hh
for update
on test
for each row
declare
begin
if updating then
if :old.names <> :new.names then
reaise_replaction_err(-2002,"關鍵字不能修改")
end if
end if
end
-- 定義遊標
declare
cursor aa is
select names,num from test;
begin
for bb in aa
loop
if bb.names = "ORACLE" then
end if
end loop;
end
-- 速度優化,前一語句不後一語句的速度快幾十倍
select names,dates
from test,b
where test.names = b.names(+) and
b.names is null and
b.dates > date('2003-01-01','yyyy-mm-dd')
select names,dates
from test
where names not in ( select names
from b
where dates > to_date('2003-01-01','yyyy-mm-dd'))
-- 查詢重複記錄
select names,num
from test
where rowid != (select max(rowid)
from test b
where b.names = test.names and
b.num = test.num)
-- 查詢表TEST中時間最新的前10條記錄
select * from (select * from test order by dates desc) where rownum < 11
-- 序列號的產生
create sequence row_id
minvalue 1
maxvalue 9999999999999999999999
start with 1
increment by 1
insert into test values(row_id.nextval,....)
文章出處:DIY部落(http://www.diybl.com/course/7_databases/oracle/2007926/73805.html#)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/11536986/viewspace-621916/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle 操作表結構基本語法及示例Oracle
- [一、基本語法]1基本語法概述
- VUE的基本語法Vue
- Python的基本語法Python
- Thymeleaf的基本語法
- C++ 的基本語法C++
- Oracle基本SQL語句OracleSQL
- Python 基本語法Python
- React基本語法React
- Redux基本語法Redux
- javascript基本語法JavaScript
- lua~基本語法
- shell基本語法
- mysql基本語法MySql
- TCP基本語法TCP
- Markdown 基本語法
- JSP基本語法JS
- Markdown基本語法
- Java基本語法Java
- PHP基本語法PHP
- 有趣的自然語言處理資源集錦自然語言處理
- Perl語法的基本規則
- markdown基本語法的學習
- oracle partition by 語法Oracle
- HTML基本語法和語義HTML
- python基本語法元素Python
- C++基本語法C++
- NLP自然語言處理中英文分詞工具集錦與基本使用介紹自然語言處理分詞
- Kotlin的基本語法和型別Kotlin型別
- 正規表示式的基本語法
- go 模板(template)的常用基本語法Go
- orcale 語句基本語法縮寫
- Scala基本語法學習
- 詳解Dockerfile基本語法Docker
- Java基本語法回顧Java
- jsx基本語法規則JS
- java基本語法--運算子Java
- AIX 5.3 Install Oracle 10g RAC 錯誤集錦AIOracle 10g
- MySQL的基本語法(增,刪,改,查)MySql