×

sqlserver存储过程 存储过程

编写一个SQLSERVER 存储过程?mysql数据库存储过程怎么写

admin admin 发表于2022-07-12 11:16:54 浏览101 评论0

抢沙发发表评论

编写一个SQLSERVER 存储过程


代码是最好的文字,不多说,请看我的代码,并给分,呵呵。
--step1. 建表
if exists(select * from sysobjects where id=object_id(’student’) and objectproperty(id,’IsTable’)=1)
drop table student
go
create table student

id int identity(100,10) not null
,sname varchar(10) not null
,sno varchar(30) not null

go
--step2.建存储过程
if exists(select * from sysobjects where id=object_id(’proc_demo’) and objectproperty(id,’IsProcedure’)=1)
drop procedure proc_demo
go
create procedure proc_demo
@o_maxid int output
as
set nocount on

--如果希望大小写敏感,使用第一句,因为SQL Server默认是大小写不敏感的
--update student set sno=’cay_’+sno where ascii(substring(sname,1,1))=87 and ascii(substring(sname,2,1))=65 and sno not like ’cay_%’
update student set sno=’cay_’+sno where sname like ’WA%’ and sno not like ’cay_%’

print convert(varchar(10),@@rowcount)+’条记录符合条件并被处理’

select @o_maxid=max(id) from student where id》=100
if(@o_maxid is null) print ’没有找到符合条件的最大记录’

set nocount off
go
--测试数据1
truncate table student
set identity_insert student on
insert into student(id,sname,sno)values(1,’WA1’,’1’);
insert into student(id,sname,sno)values(2,’wa2’,’2’);
insert into student(id,sname,sno)values(3,’3’,’3’);
set identity_insert student off
go
--测试数据2
truncate table student
insert into student(sname,sno)values(’WA1’,’1’);
insert into student(sname,sno)values(’wa2’,’2’);
insert into student(sname,sno)values(’3’,’3’);
go
--测试过程
declare @maxid int
exec proc_demo @maxid out
print ’最大id是’+convert(varchar(10),@maxid)
go

mysql数据库存储过程怎么写


创建存储过程
mysql》
delimiter
$
--
delimiter
$是设置
$为命令终止符号,代替默认的分号,因为分号有其他用处.
mysql》
create
procedure
sp_test(IN
pi_id
int,
OUT
po_name
varchar(10))
-》
begin
-》
select
*
from
test.tb_test;
-》
select
tb_test.name
into
po_name
from
test.tb_test
where
tb_test.id
=
pi_id;
-》
end
-》
$
Query
OK,
0
rows
affected
(0.00
sec)
mysql》
delimiter
;
--
恢复分号作为分隔终止符号
5.调用存储过程
mysql》
set
@po_name=’’;
Query
OK,
0
rows
affected
(0.00
sec)
mysql》
call
sp_test(1,@po_name);

如何编写数据库存储过程

存储过程代码参考如下:createorreplaceprocedurebak_pay_list_xxx(local_netinvarchar2,bak_monthinvarchar2,retoutvarchar2)isls_sqlvarchar2(1024);ls_sql_delvarchar2(1024);begin...endbak_pay_list_xxx;-sqlserver存储过程