sql: Oracle 11g create procedure
CREATE OR REPLACE PROCEDURE proc_Insert_BookKindList
(
temTypeName nvarchar2,
temParent int
)
AS
ncount number;
begin
--SELECT COUNT (*) INTO ncount FROM BookKindList fm1 where EXISTS (SELECT BookKindName from BookKindList fm2 where fm2.BookKindName=temTypeName);--判斷是否存
SELECT count(*) INTO ncount FROM BookKindList where BookKindName=temTypeName;
if ncount<=0 then
begin
INSERT INTO BookKindList (BookKindName,BookKindParent) VALUES(temTypeName,temParent);
commit;
end;
else
begin
SELECT BookKindID INTO ncount FROM BookKindList where BookKindName=temTypeName;
dbms_output.put_line('存在相同的记录,添加不成功!'||ncount);
end;
end if;
Exception
When others then
dbms_output.put_line('存在问题,添加不成功!'||ncount);
Rollback;
end proc_Insert_BookKindList; --测试 oracle 11g 涂聚文 20150526
exec proc_Insert_BookKindList ('油彩画',3); drop PROCEDURE proc_Insert_BookKindOut; CREATE OR REPLACE PROCEDURE procInsertBookKindOut --添加返回ID
(
temTypeName nvarchar2,
temParent number,
temId out number
)
AS
ncount number;
reid number;
begin
--SELECT COUNT (*) INTO ncount FROM BookKindList fm1 where EXISTS (SELECT BookKindName from BookKindList fm2 where fm2.BookKindName=temTypeName);--判斷是否存
SELECT count(*) INTO ncount FROM BookKindList where BookKindName=temTypeName;
if ncount<=0 then
begin
INSERT INTO BookKindList (BookKindID,BookKindName,BookKindParent) VALUES(BookKindList_SEQ.nextval,temTypeName,temParent);
select BookKindList_SEQ.currval into reid from dual;
temId:=reid;
dbms_output.put_line('添加成功!'||temId);
commit;
end;
else
begin
SELECT BookKindID INTO ncount FROM BookKindList where BookKindName=temTypeName;
dbms_output.put_line('存在相同的记录,添加不成功!'||ncount);
temId:=0;
end;
end if;
Exception
When others then
begin
dbms_output.put_line('存在问题,添加不成功!'||ncount);
temId:=0;
Rollback;
end;
end procInsertBookKindOut; --测试 oracle 11g 涂聚文 20150526
declare
mid number:=0;
nam nvarchar2(100):='黑白画';
par number:=3;
begin
--proc_Insert_BookKindOut(nam in nvarchar2,par in int,mid in out int);
procInsertBookKindOut(nam,par ,mid);
if mid>0 then
dbms_output.put_line('添加成功!输出参数:'||mid);
else
dbms_output.put_line('存在相同的记录,添加不成功!输出参数:'||mid);
end if;
end;
csharp 调用:
///<summary>
/// 追加记录
///</summary>
///<param name="BookKindListInfo"></param>
///<returns></returns>
public int InsertBookKindList(BookKindListInfo bookKindList)
{
int ret = 0;
try
{
OracleParameter[] par = new OracleParameter[]{
new OracleParameter("temTypeName",OracleType.NVarChar,1000),
new OracleParameter("temParent",OracleType.Number,4),
};
par[0].Value = bookKindList.BookKindName;
par[1].Value = bookKindList.BookKindParent;
ret = OracleHelper.ExecuteSql("proc_Insert_BookKindList", CommandType.StoredProcedure, par);
}
catch (OracleException ex)
{
throw ex;
}
return ret;
}
/// <summary>
/// 追加记录返回
/// </summary>
/// <param name="authorList"></param>
/// <param name="authorID"></param>
/// <returns></returns>
public int InsertBookKindOutput(BookKindListInfo bookKindList, out int bookKindLID)
{
bookKindLID = 0;
int ret = 0;
try
{
OracleParameter[] par = new OracleParameter[]{
new OracleParameter("temTypeName",OracleType.NVarChar,1000),
new OracleParameter("temParent",OracleType.Number,4),
new OracleParameter("temId",OracleType.Number,4),
};
par[0].Value = bookKindList.BookKindName;
par[1].Value = bookKindList.BookKindParent;
par[2].Direction = ParameterDirection.Output;
ret = OracleHelper.ExecuteSql("proc_Insert_BookKindOut", CommandType.StoredProcedure, par);
if (ret > 0)
{
bookKindLID =int.Parse(par[2].Value.ToString());
}
}
catch (OracleException ex)
{
throw ex;
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
BookKindListInfo bookKindListInfo = new BookKindListInfo();
BookKindListBLL bookKindListBLL = new BookKindListBLL();
bookKindListInfo.BookKindParent =(int)this.numericUpDownBookKindParent.Value;
bookKindListInfo.BookKindName = this.textBoxBookKindName.Text.Trim(); int k = 0;
k = bookKindListBLL.InsertBookKindList(bookKindListInfo);
if (k > 0)
{
MessageBox.Show("ok");
}
else
{
MessageBox.Show("no");
} }
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
BookKindListInfo bookKindListInfo = new BookKindListInfo();
BookKindListBLL bookKindListBLL = new BookKindListBLL();
bookKindListInfo.BookKindParent = (int)this.numericUpDownBookKindParent.Value;
bookKindListInfo.BookKindName = this.textBoxBookKindName.Text.Trim();
int ou = 0;
int k = 0;
k = bookKindListBLL.InsertBookKindOutput(bookKindListInfo,out ou);
if (k > 0)
{
MessageBox.Show("ok:id"+ou.ToString());
}
else
{
MessageBox.Show("no");
}
}
sql: Oracle 11g create procedure的更多相关文章
- sql: Oracle 11g create table, function,trigger, sequence
--书藉位置Place目录 drop table BookPlaceList; create table BookPlaceList ( BookPlaceID INT PRIMARY KEY, -- ...
- Oracle 11g 中SQL性能优化新特性之SQL性能分析器(SQLPA)
Oracle11g中,真实应用测试选项(the Real Application Testing Option)提供了一个有用的特点,叫SQL性能分析器(SQL Performance Analyze ...
- Oracle 11g R2性能优化 SQL TRACE
作为Oracle官方自带的一种基本性能诊断工具,SQL Trace可以用来评估当前正在运行的SQL语句的效率,同时为该语句生成统计信息等,并保存这些信息到指定路径下的跟踪文件(trace)当中.SQL ...
- PL/SQL Developer连接本地Oracle 11g 64位数据库和快捷键设置
1.登录PL/SQL Developer 这里省略Oracle数据库和PL/SQL Developer的安装步骤,注意在安装PL/SQL Developer软件时,不要安装在Program Files ...
- SQL SERVER 2008向ORACLE 11G迁移示例
来源于:http://www.cnblogs.com/hiizsk/ 由SQL SERVER 2008向ORACLE 11G迁移过程记录之一-表 使用Oracle Sql Developer将SQL ...
- In Oracle 11g, how to change the order of the results of a sql without “order by”?(转)
oracle 11g 当sql语句中不加order by的时候,好像是按rowid的顺序返回结果的.我也看过一些相关的文档,oracle的官方意思就是不加order by,就不保证输出的顺序. 那么, ...
- 使用Oracle Sql Developer将SQL SERVER 2008数据库移植到Oracle 11g
ORACLE官方提供的Sql Developer自带的Oracle Migration Workbench. 什么是Oracle SQL Developer?在官方页面上,是这样介绍它的: Oracl ...
- Oracle 11g XE 与 Oracle SQL Developer 的配置与使用(重制版)
Oracle 11g XE 与 Oracle SQL Developer 的配置与使用(重制版) 前提概要 项目上需求要适应Oracle数据库,当然这和某EF框架也有关. 因为Oracle 的表名和列 ...
- PL/SQL Developer连接本地Oracle 11g 64位数据库
转摘:http://www.cnblogs.com/ymj126/p/3712727.html 用于学习,笔记,以备后用. 1.登录PL/SQL Developer 这里省略Oracle数据库和PL/ ...
随机推荐
- 字符串模式匹配算法1 - BF和KMP算法
在字符串S中定位/查找某个子字符串P的操作,通常称为字符串的模式匹配,其中P称为模式串.模式匹配有多种算法,这里先总结一下BF算法和KMP算法. 注意:本文在讨论字符位置/指针/下标时,全部使用C语法 ...
- jquery scrollTop()与scrollLeft()
1.scrollLeft() scrollLeft() 方法设置或返回被选元素的水平滚动条位置. 提示:当滚动条位于最左侧时,位置是 0. 当用于返回位置时:该方法返回第一个匹配元素的滚动条的水平位置 ...
- i2c_smbs 函数
i2c_smbus系列函数有: s32 i2c_smbus_read_byte(const struct i2c_client *client); s32 i2c_smbus_write_byte(c ...
- Android NDK开发及OpenCV初步学习笔记
https://www.jianshu.com/p/c29bb20908da Android NDK开发及OpenCV初步学习笔记 Super_圣代 关注 2017.08.19 00:55* 字数 6 ...
- VS 代码自动对齐快捷键
全部代码代码自动对齐快捷键为 Ctrl + a(按后可松松手) + k(按后可松松手) + f
- 一段自用javascript代码
function jsontoarray(mjson) { var arr = []; ; for(var x in mjson.data){ arr[i] = new Array(); arr[i] ...
- JVectorMap地图插件.Net版开源
jVectorMap地图插件只要浏览器技术JavaScript.CSS,HTML,SVG或VML就可以浏览使用,不需要Flash或其他专有的浏览 器插件.所以jVectorMap在所有现代移动浏览器上 ...
- CentOS7编译curl
1.下载curl源代码 https://curl.haxx.se/download.html 2.进入curl目录 ./configure --prefix=/usr/local/curl make ...
- jQuery Mobile 实现苹果滑动删除闹钟功能的几点总结
1.jquery给动态添加的元素添加事件 在jquery推出新版本,使用.on()以前,我们会用.live()来为动态添加的代码绑定事件,但是现在jQuery用.on()替代了.live() 先看个. ...
- 一头扎进Spring之---------Spring七大核心模块
Spring七大核心模块 核心容器(Spring Core) 核心容器提供Spring框架的基本功能.Spring以bean的方式组织和管理Java应用中的各个组件及其关系.Spring使用BeanF ...