代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
PLSQL
】
oracle增刪改查存儲過程
作者:
Dezai.CN
/ 发布于
2011/7/7
/
739
<div><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)">--創建增刪改查的包</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,255)">CREATE</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,128,128)">OR</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(255,0,255)">REPLACE</span><span style="color: rgb(0,0,0)"> package TESTPACKAGE </span><span style="color: rgb(0,0,255)">IS</span><span style="color: rgb(0,0,0)"> TYPE mycursor </span><span style="color: rgb(0,0,255)">IS</span><span style="color: rgb(0,0,0)"> REF </span><span style="color: rgb(0,0,255)">CURSOR</span><span style="color: rgb(0,0,0)">; type mycursorid </span><span style="color: rgb(0,0,255)">is</span><span style="color: rgb(0,0,0)"> ref </span><span style="color: rgb(0,0,255)">cursor</span><span style="color: rgb(0,0,0)">; type mycursorLike </span><span style="color: rgb(0,0,255)">is</span><span style="color: rgb(0,0,0)"> ref </span><span style="color: rgb(0,0,255)">cursor</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)">-模糊查詢</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,0)">type mycursor1 </span><span style="color: rgb(0,0,255)">is</span><span style="color: rgb(0,0,0)"> ref </span><span style="color: rgb(0,0,255)">cursor</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)">多條件查詢</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,255)">PROCEDURE</span><span style="color: rgb(0,0,0)"> updateRecords(v_first_name </span><span style="color: rgb(128,128,128)">in</span><span style="color: rgb(0,0,0)"> tb1.first_name</span><span style="color: rgb(128,128,128)">%</span><span style="color: rgb(0,0,0)">type,v_name </span><span style="color: rgb(128,128,128)">in</span><span style="color: rgb(0,0,0)"> tb1.name</span><span style="color: rgb(128,128,128)">%</span><span style="color: rgb(0,0,0)">type); </span><span style="color: rgb(0,0,255)">PROCEDURE</span><span style="color: rgb(0,0,0)"> deleteRecords(v_first_name </span><span style="color: rgb(128,128,128)">in</span><span style="color: rgb(0,0,0)"> tb1.first_name</span><span style="color: rgb(128,128,128)">%</span><span style="color: rgb(0,0,0)">type); </span><span style="color: rgb(0,0,255)">procedure</span><span style="color: rgb(0,0,0)"> selectRecords(ref_cursor out mycursor); </span><span style="color: rgb(0,0,255)">procedure</span><span style="color: rgb(0,0,0)"> insertRecords(v_name </span><span style="color: rgb(128,128,128)">in</span><span style="color: rgb(0,0,0)"> tb1.name</span><span style="color: rgb(128,128,128)">%</span><span style="color: rgb(0,0,0)">type); </span><span style="color: rgb(0,0,255)">procedure</span><span style="color: rgb(0,0,0)"> selectByIdRecords(v_first_name </span><span style="color: rgb(128,128,128)">in</span><span style="color: rgb(0,0,0)"> tb1.first_name</span><span style="color: rgb(128,128,128)">%</span><span style="color: rgb(0,0,0)">type,ref_cursorid out mycursorid); </span><span style="color: rgb(0,0,255)">procedure</span><span style="color: rgb(0,0,0)"> selectAllByNameRecords(ref_likecursor out mycursorLike,v_name </span><span style="color: rgb(128,128,128)">in</span><span style="color: rgb(0,0,0)"> tb1.name</span><span style="color: rgb(128,128,128)">%</span><span style="color: rgb(0,0,0)">type); </span><span style="color: rgb(0,0,255)">procedure</span><span style="color: rgb(0,0,0)"> selectTbTest(ref_cur out mycursor1,i_name </span><span style="color: rgb(128,128,128)">in</span><span style="color: rgb(0,0,0)"> tb_test.name</span><span style="color: rgb(128,128,128)">%</span><span style="color: rgb(0,0,0)">type, i_sex </span><span style="color: rgb(128,128,128)">in</span><span style="color: rgb(0,0,0)"> tb_test.sex</span><span style="color: rgb(128,128,128)">%</span><span style="color: rgb(0,0,0)">type, i_age </span><span style="color: rgb(128,128,128)">in</span><span style="color: rgb(0,0,0)"> tb_test.age</span><span style="color: rgb(128,128,128)">%</span><span style="color: rgb(0,0,0)">type); </span><span style="color: rgb(0,0,255)">END</span><span style="color: rgb(0,0,0)"> TESTPACKAGE; </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)">創建增刪改查的包體</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,255)">CREATE</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,128,128)">OR</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(255,0,255)">REPLACE</span><span style="color: rgb(0,0,0)"> package body TESTPACKAGE </span><span style="color: rgb(0,0,255)">IS</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)">修改的</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,255)">PROCEDURE</span><span style="color: rgb(0,0,0)"> updateRecords(v_first_name </span><span style="color: rgb(128,128,128)">in</span><span style="color: rgb(0,0,0)"> tb1.first_name</span><span style="color: rgb(128,128,128)">%</span><span style="color: rgb(0,0,0)">type,v_name </span><span style="color: rgb(128,128,128)">in</span><span style="color: rgb(0,0,0)"> tb1.name</span><span style="color: rgb(128,128,128)">%</span><span style="color: rgb(0,0,0)">type) </span><span style="color: rgb(0,0,255)">is</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">begin</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">update</span><span style="color: rgb(0,0,0)"> tb1 </span><span style="color: rgb(0,0,255)">set</span><span style="color: rgb(0,0,0)"> name</span><span style="color: rgb(128,128,128)">=</span><span style="color: rgb(0,0,0)">v_name </span><span style="color: rgb(0,0,255)">where</span><span style="color: rgb(0,0,0)"> first_name</span><span style="color: rgb(128,128,128)">=</span><span style="color: rgb(0,0,0)">v_first_name; </span><span style="color: rgb(0,0,255)">end</span><span style="color: rgb(0,0,0)"> updateRecords; </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)">查詢的</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,255)">PROCEDURE</span><span style="color: rgb(0,0,0)"> selectRecords(ref_cursor out mycursor) </span><span style="color: rgb(0,0,255)">IS</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">BEGIN</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">OPEN</span><span style="color: rgb(0,0,0)"> ref_cursor </span><span style="color: rgb(0,0,255)">for</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">select</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,128,128)">*</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">from</span><span style="color: rgb(0,0,0)"> tb1; </span><span style="color: rgb(0,0,255)">END</span><span style="color: rgb(0,0,0)"> selectRecords; </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)">刪除的</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,255)">procedure</span><span style="color: rgb(0,0,0)"> deleteRecords(v_first_name </span><span style="color: rgb(128,128,128)">in</span><span style="color: rgb(0,0,0)"> tb1.first_name</span><span style="color: rgb(128,128,128)">%</span><span style="color: rgb(0,0,0)">type) </span><span style="color: rgb(0,0,255)">is</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">begin</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">delete</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">from</span><span style="color: rgb(0,0,0)"> tb1 </span><span style="color: rgb(0,0,255)">where</span><span style="color: rgb(0,0,0)"> first_name</span><span style="color: rgb(128,128,128)">=</span><span style="color: rgb(0,0,0)">v_first_name; </span><span style="color: rgb(0,0,255)">end</span><span style="color: rgb(0,0,0)"> deleteRecords; </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)">增加的</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,255)">procedure</span><span style="color: rgb(0,0,0)"> insertRecords(v_name </span><span style="color: rgb(128,128,128)">in</span><span style="color: rgb(0,0,0)"> tb1.name</span><span style="color: rgb(128,128,128)">%</span><span style="color: rgb(0,0,0)">type) </span><span style="color: rgb(0,0,255)">is</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">begin</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">insert</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">into</span><span style="color: rgb(0,0,0)"> tb1(first_name,name) </span><span style="color: rgb(0,0,255)">values</span><span style="color: rgb(0,0,0)">(squ_cg_test.nextval,v_name); </span><span style="color: rgb(0,0,255)">end</span><span style="color: rgb(0,0,0)"> insertRecords; </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)">根據id查找該條信息</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,255)">procedure</span><span style="color: rgb(0,0,0)"> selectByIdRecords(v_first_name </span><span style="color: rgb(128,128,128)">in</span><span style="color: rgb(0,0,0)"> tb1.first_name</span><span style="color: rgb(128,128,128)">%</span><span style="color: rgb(0,0,0)">type,ref_cursorid out mycursorid) </span><span style="color: rgb(0,0,255)">is</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">begin</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">open</span><span style="color: rgb(0,0,0)"> ref_cursorid </span><span style="color: rgb(0,0,255)">for</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">select</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,128,128)">*</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">from</span><span style="color: rgb(0,0,0)"> tb1 </span><span style="color: rgb(0,0,255)">where</span><span style="color: rgb(0,0,0)"> first_name</span><span style="color: rgb(128,128,128)">=</span><span style="color: rgb(0,0,0)">v_first_name; </span><span style="color: rgb(0,0,255)">end</span><span style="color: rgb(0,0,0)"> selectByIdRecords; </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)">模糊查詢</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,255)">procedure</span><span style="color: rgb(0,0,0)"> selectAllByNameRecords(ref_likecursor out mycursorLike,v_name </span><span style="color: rgb(128,128,128)">in</span><span style="color: rgb(0,0,0)"> tb1.name</span><span style="color: rgb(128,128,128)">%</span><span style="color: rgb(0,0,0)">type) </span><span style="color: rgb(0,0,255)">is</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">begin</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">open</span><span style="color: rgb(0,0,0)"> ref_likecursor </span><span style="color: rgb(0,0,255)">for</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">select</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,128,128)">*</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">from</span><span style="color: rgb(0,0,0)"> tb1 </span><span style="color: rgb(0,0,255)">where</span><span style="color: rgb(0,0,0)"> name </span><span style="color: rgb(128,128,128)">like</span><span style="color: rgb(0,0,0)"> v_name</span><span style="color: rgb(128,128,128)">||</span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(255,0,0)">%</span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">end</span><span style="color: rgb(0,0,0)"> selectAllByNameRecords; </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)">多條件查詢模糊查詢</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,255)">procedure</span><span style="color: rgb(0,0,0)"> selectTbTest( ref_cur out mycursor1, i_name </span><span style="color: rgb(128,128,128)">in</span><span style="color: rgb(0,0,0)"> tb_test.name</span><span style="color: rgb(128,128,128)">%</span><span style="color: rgb(0,0,0)">type, i_sex </span><span style="color: rgb(128,128,128)">in</span><span style="color: rgb(0,0,0)"> tb_test.sex</span><span style="color: rgb(128,128,128)">%</span><span style="color: rgb(0,0,0)">type, i_age </span><span style="color: rgb(128,128,128)">in</span><span style="color: rgb(0,0,0)"> tb_test.age</span><span style="color: rgb(128,128,128)">%</span><span style="color: rgb(0,0,0)">type ) </span><span style="color: rgb(0,0,255)">is</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">begin</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">open</span><span style="color: rgb(0,0,0)"> ref_cur </span><span style="color: rgb(0,0,255)">for</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">select</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,128,128)">*</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">from</span><span style="color: rgb(0,0,0)"> tb_test </span><span style="color: rgb(0,0,255)">where</span><span style="color: rgb(0,0,0)"> ( name </span><span style="color: rgb(128,128,128)">like</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(255,0,0)">%</span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(128,128,128)">||</span><span style="color: rgb(0,0,0)">i_name</span><span style="color: rgb(128,128,128)">||</span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(255,0,0)">%</span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,128,128)">or</span><span style="color: rgb(0,0,0)"> i_name </span><span style="color: rgb(0,0,255)">is</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">null</span><span style="color: rgb(0,0,0)">) </span><span style="color: rgb(128,128,128)">and</span><span style="color: rgb(0,0,0)"> ( sex </span><span style="color: rgb(128,128,128)">=</span><span style="color: rgb(0,0,0)"> i_sex </span><span style="color: rgb(128,128,128)">or</span><span style="color: rgb(0,0,0)"> i_sex </span><span style="color: rgb(0,0,255)">is</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">null</span><span style="color: rgb(0,0,0)">) </span><span style="color: rgb(128,128,128)">and</span><span style="color: rgb(0,0,0)"> ( age </span><span style="color: rgb(128,128,128)">=</span><span style="color: rgb(0,0,0)"> i_age </span><span style="color: rgb(128,128,128)">or</span><span style="color: rgb(0,0,0)"> i_age </span><span style="color: rgb(0,0,255)">is</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">null</span><span style="color: rgb(0,0,0)">); </span><span style="color: rgb(0,0,255)">end</span><span style="color: rgb(0,0,0)"> selectTbTest; </span><span style="color: rgb(0,0,255)">end</span><span style="color: rgb(0,0,0)"> TESTPACKAGE; </span></div>
试试其它关键字
增刪改查
同语言下
.
查看某张表的表结构
.
oracle 集合操作
.
for 循环中倒序 用reverse
.
Oracle 临时表空间收缩
.
查看session及其对应运行的sql
.
Oracle常用查看表结构命令
.
Oracle Connect By Prior用法(实现递归查询)
.
重置排序 SEQUENCE
.
创建一个trigger
.
批量替换字段中的字符
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3