sql存储过程select
⑴ 用sql如何调用存储过程 select * 存储过程名 from al
是oracle吧,如果存储过程里不带参数,按下边的方法
begin
存储过程名;
end;
如果带参数
begin
存储过程名(v_ym => :v_ym);
end;
其中v_ym是输入参数
也或者,你用plsql的话,找到左边的树procere,右键选中你的过程名-测试-执行(如果有输入参数直接输入参数就行了)
看你写的语句,你是要查你都建了那些存储过程吧?
select * from USER_OBJECTS where OBJECT_TYPE='PROCEDURE';
其中,引号里那个PROCEDURE必须大写
⑵ 怎么用sql select语句查存储过程
有时候你没有办法使用图形界面的管理器连接SQL 服务器,这个时候如果你想查看一个存
储过程的内容就只能依靠SQL 语句了。
系统提供了一个存储过程可以查看 rule,stored procere, user-defined function,
trigger, 或者 view。Syntaxsp_helptext @objname = 'name'
sp_helptext '存储过程名称'
⑶ 在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%';
(3)sql存储过程select扩展阅读:
SQL存储过程优点:
1、重复使用。存储过程可以重复使用,从而可以减少数据库开发人员的工作量。
2、减少网络流量。存储过程位于服务器上,调用的时候只需要传递存储过程的名称以及参数就可以了,因此降低了网络传输的数据量。
3、安全性。参数化的存储过程可以防止SQL注入式攻击,而且可以将Grant、Deny以及Revoke权限应用于存储过程。
⑷ SQL 中存储过程怎么使用
一、简单的储存过程:
1、创建一个存储过程
create procere GetUsers()
begin
select * from user;
end;12345
2、调用存储过程
call GetUsers();12
3、删除存储过程
drop procere if exists GetUsers;
二、带参数的存储过程
1、MySql 支持 IN (传递给存储过程) , OUT (从存储过程传出) 和 INOUT (对存储过程传入和传出) 类型的参数 , 存储过程的代码位于 BEGIN 和 END 语句内 , 它们是一系列 SQL 语句 , 用来检索值 , 然后保存到相应的变量 (通过指定INTO关键字) ;
2、下面的存储过程接受三个参数 , 分别用于获取用户表的最小 , 平均 , 最大分数 , 每个参数必须具有指定的类型 , 这里使用十进制值(decimal(8,2)) , 关键字 OUT 指出相应的参数用来从存储过程传出
create procere GetScores(
out minScore decimal(8,2),
out avgScore decimal(8,2),
out maxScore decimal(8,2)
)
begin
select min(score) into minScore from user;
select avg(score) into avgScore from user;
select max(score) into maxScore from user;
end;1234567891011
3、调用此存储过程 , 必须指定3个变量名(所有 MySql 变量都必须以@开始) , 如下所示 :
call GetScores(@minScore, @avgScore, @maxScore);12
4、该调用并没有任何输出 , 只是把调用的结果赋给了调用时传入的变量@minScore, @avgScore, @maxScore, 然后即可调用显示该变量的值 :
select @minScore, @avgScore, @maxScore;
5、使用 IN 参数 , 输入一个用户 id , 返回该用户的名字 :
create procere GetNameByID(
in userID int,
out userName varchar(200)
)
begin
select name from user
where id = userID
into userName;
end;12345678910
6、调用存储过程 :
call GetNameByID(1, @userName);
select @userName;123
⑸ 在 sql select 语句中 如何获取 存储过程的返回值
SQL Server中存储过程的返回值不是通过return语句返回的(return语句是在用户自定义函数中使用的),而是通过存储过程的参数来返回,在定义存储过程的参数时使用关键字output来指定此参数是返回值。
而在调用存储过程时,也必须使用关键字给接收返回值的变量,这样才能在调用时获得存储过程的返回值。
示例:
createproceredbo.pr_add@aint,@bint,@cintoutput
as
set@c=@a+@b
go
调用:
declare@vint
executedbo.pr_add1,2,@voutput
select@v