欢迎来到天天文库
浏览记录
ID:39774541
大小:37.50 KB
页数:8页
时间:2019-07-11
《ORACLE数据库的基本语法集锦》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、ORACLE数据库的基本语法集锦--表createtabletest(namesvarchar2(12), datesdate, num int, dou double);--视图createorreplaceviewvi_testasselect*fromtest;--同义词createorreplacesynonymaafordbusrcard001.aa;--存储过程createorreplaceproducedd(v_idinemployee.empoy_id%type)asbeg
2、in enddd;--函数createorreplacefunctionee(v_idinemployee%rowtype)returnvarchar(15)isvar_testvarchar2(15);begin returnvar_test;exceptionwhenothersthen end--三种触发器的定义createorreplacetriggerffalterdeleteontestforeachrowdeclarebegin deletefromtest; ifsql%rowcount<0orsql%rowcountisnullthen rais_replac
3、tion_err(-20004,"错误") endifendcreateorreplacetriggerggalterinsertontestforeachrowdeclarebegin if:old.names=:new.namesthen raise_replaction_err(-2003,"编码重复"); endifendcreateorreplacetriggerhhforupdateontestforeachrowdeclarebegin ifupdatingthen if:old.names<>:new.namesthen reaise_replaction_
4、err(-2002,"关键字不能修改") endif endifend--定义游标declare cursoraais selectnames,numfromtest;begin forbbinaa loop ifbb.names="ORACLE"then endif endloop; end--速度优化,前一语句不后一语句的速度快几十倍selectnames,datesfromtest,bwheretest.names=b.names(+)and b.namesisnulland b.dates>date('200
5、3-01-01','yyyy-mm-dd')selectnames,datesfromtestwherenamesnotin(selectnames fromb wheredates>to_date('2003-01-01','yyyy-mm-dd')) --查找重复记录selectnames,numfromtestwhererowid!=(selectmax(rowid) fromtestb whereb.nam
6、es=test.namesand b.num=test.num)--查找表TEST中时间最新的前10条记录select*from(select*fromtestorderbydatesdesc)whererownum<11--序列号的产生createsequencerow_idminvalue1maxvalue9999999999999999999999startwith1incrementby1insertintotestvalues(row_id.nextval,....) 存储过程1.基本结构CREATEORREPLACEPROCEDURE存储过程
7、名字( 参数1INNUMBER, 参数2INNUMBER)IS变量1INTEGER:=0;变量2DATE;BEGINEND存储过程名字 2.SELECTINTOSTATEMENT 将select查询的结果存入到变量中,可以同时将多个列存储多个变量中,必须有一条 记录,否则抛出异常(如果没有记录抛出NO_DATA_FOUND) 例子: BEGIN SELECTcol1,col2into变量1
此文档下载收益归作者所有