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,....)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10172717/viewspace-926881/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ORACLE的基本語法集錦Oracle
- Oracle 10g基本語法Oracle 10g
- PL/SQL基本語法要素(轉)SQL
- [一、基本語法]1基本語法概述
- Oracle儲存過程基本語法Oracle儲存過程
- VUE的基本語法Vue
- Thymeleaf的基本語法
- 【轉載】oracle更新語法Oracle
- Java 語法介紹(一):Java語言的基本組成(轉)Java
- Python的基本語法Python
- C++ 的基本語法C++
- Markdown 基本語法
- javascript基本語法JavaScript
- PHP基本語法PHP
- Redux基本語法Redux
- React基本語法React
- ajax 基本語法
- VBS基本語法
- mongoDB基本語法MongoDB
- factory基本語法
- SQL基本語法SQL
- VB基本語法
- Java基本語法Java
- shell基本語法
- TCP基本語法TCP
- Markdown基本語法
- mysql基本語法MySql
- lua~基本語法
- Oracle 操作表結構基本語法及示例Oracle
- [轉]XML檔案結構和基本語法XML
- Perl語法的基本規則
- markdown基本語法的學習
- Python 基本語法Python
- JSP基本語法JS
- C++基本語法C++
- HTML基本語法和語義HTML
- Oracle SQL Loader的詳細語法 <轉>OracleSQL
- 常用的oracle基本語句Oracle