sql存储过程写法参数
A. sql server 中 一个要输入参数和输出参数的存储过程。
第一步:点击数据库下的“可编程性”,选择“存储过程”,点击鼠标右键,选择“新建存储过程”
第二步:在create
PROCEDURE
后输入存储过程的名字,紧跟着的就是定义存储过程的参数,接下来就可以去编写自己所需要组装的存储过程语句了
注意,怕写的不对,可以执行下,想验证sql语句是否正确,就使用print输出下
第三步:点击上面的执行,存储过程就写好了,要怎么调用呢,在sqlserver的语句查询框中,输入exec
存储过程名
参数,执行就可以了。

B. sql server 中 一个要输入参数和输出参数的存储过程。
1、首先我们需要打开SQL Server Managment管理工具,新建一个表。

C. sqlserver怎么创建存储过程
SQL创建存储过程的基础语法是:
create proc | procere pro_name
[{@参数数据类型}=[默认值][output], {@参数数据类型}=[默认值][output], .... ]
as
SQL_statements
常见的创建存储过程实例如下:
1、创建不带参数的存储过程:
create proc proc_get_student
as
select*from student;
执行存储过程:
exec proc_get_student;
2、带参数的存储过程:
create proc proc_find_stu(@startId int, @endId int)
as
select*from student where id between @startId and @endId;
执行存储过程:
exec proc_find_stu 2, 4;
3、带通配符参数的存储过程:
create proc proc_findStudentByName(@name varchar(20)='%j%', @nextName varchar(20)='%')
as
select*from student where name like @name and name like @nextName;
执行存储过程:
exec proc_findStudentByName;
exec proc_findStudentByName '%o%', 't%';
4、带输出参数的存储过程:
create proc proc_getStudentRecord( @id int, -- 默认输入参数
@name varchar(20) out, -- 输出参数
@age varchar(20) output -- 输入输出参数 )
as
select @name = name, @age = age from student where id = @id and sex = @age;
执行存储过程:
declare @id int, @name varchar(20), @temp varchar(20);
set @id = 7;
set @temp = 1;
exec proc_getStudentRecord @id, @name out, @temp output;
select @name, @temp;
print @name + '#' + @temp;
D. MySQL里面sql语句调用存储过程,该如何写
这样:
CREATEPROCEDUREsp_add(a int, b int,outc int)
begin
set c=a+ b;
end;
调用过程:
call sp_add (1,2,@a);
select @a;

(4)sql存储过程写法参数扩展阅读:
注意事项
存储过程(stored procere)是一组为了完成特定功能的SQL语句集合,经编译后存储在服务器端的数据库中,利用存储过程可以加速SQL语句的执行。
存储过程分为系统存储过程和自定义存储过程。
系统存储过程在master数据库中,但是在其他的数据库中可以直接调用,并且在调用时不必在存储过程前加上数据库名,因为在创建一个新数据库时,系统存储过程在新的数据库中会自动创建。
自定义存储过程,由用户创建并能完成某一特定功能的存储过程,存储过程既可以有参数又有返回值,但是它与函数不同,存储过程的返回值只是指明执行是否成功,并不能像函数那样被直接调用,只能利用execute来执行存储过程。
创建存储过程
SQL Server创建存储过程:
create procere 过程名
@parameter 参数类型
@parameter 参数类型
。。。
as
begin
end
执行存储过程:execute 过程名
E. 在SQL中存储过程的一般语法是什么
1、 创建语法
createproc|procerepro_name
[{@参数数据类型}[=默认值][output],
{@参数数据类型}[=默认值][output],
....
]
as
SQL_statements
2、 创建不带参数存储过程
--创建存储过程
if(exists(select*fromsys.objectswherename='proc_get_student'))
dropprocproc_get_student
go
createprocproc_get_student
as
select*fromstudent;
--调用、执行存储过程
execproc_get_student;
3、 修改存储过程
--修改存储过程
alterprocproc_get_student
as
select*fromstudent;
4、 带参存储过程
--带参存储过程
if(object_id('proc_find_stu','P')isnotnull)
dropprocproc_find_stu
go
createprocproc_find_stu(@startIdint,@endIdint)
as
select*fromstudentwhereidbetween@startIdand@endId
go
execproc_find_stu2,4;
5、 带通配符参数存储过程
--带通配符参数存储过程
if(object_id('proc_findStudentByName','P')isnotnull)
dropprocproc_findStudentByName
go
createprocproc_findStudentByName(@namevarchar(20)='%j%',@nextNamevarchar(20)='%')
as
select*fromstudentwherenamelike@nameandnamelike@nextName;
go
execproc_findStudentByName;execproc_findStudentByName'%o%','t%';

(5)sql存储过程写法参数扩展阅读:
SQL存储过程优点:
1、重复使用。存储过程可以重复使用,从而可以减少数据库开发人员的工作量。
2、减少网络流量。存储过程位于服务器上,调用的时候只需要传递存储过程的名称以及参数就可以了,因此降低了网络传输的数据量。
3、安全性。参数化的存储过程可以防止SQL注入式攻击,而且可以将Grant、Deny以及Revoke权限应用于存储过程。
F. sql储存过程怎么定义参数
create
proc
存储过程名
[
{@参数1
数据带蔽弯类型}
[=默认值]
[output],
...,
{@参蠢闷数n
数并喊据类型}
[=默认值]
[output],
]
as
SQL语句
