请高手指点一下,这存储过程的语法哪里有问题,这些参数不能直接用吗

2024-05-13

1. 请高手指点一下,这存储过程的语法哪里有问题,这些参数不能直接用吗

12行select from 从表中查询,你有@Tablename这个表么

请高手指点一下,这存储过程的语法哪里有问题,这些参数不能直接用吗

2. 请问这个存储过程哪里有问题,为什么给参数执行都是说password附近有语法错误,不给参数执行可以通过

动态语句中的where条件字段类型应该都是字符串类型的,而你没有加单引号。字符串中可以用2个单引号来表示实际的一个单引号,如下


ALTER PROCEDURE [dbo].[userLogin] 
(
@userName nvarchar(30),
@passWord nvarchar(60),
@tableName varchar(20)
)
AS
 declare @strSql nvarchar(300)
 set @strSql=N'select userName,passWord from '+@tableName+' where userName='''+@userName+''' and passWord='''+@passWord+''''
execute(@strSql)

3. SQL下,写了一个存储过程,但是在执行时总是提示【没有参数,但却为该过程提供了参数】。

你没有定义参数,而在执行时却提供了2个参数!
估计是你语法不熟悉吧。
----------------
CREATE PROCEDURE proName (
    @param1    DataType

    ,@param2    DataType = 缺省值

) AS
BEGIN
    ...

END

SQL下,写了一个存储过程,但是在执行时总是提示【没有参数,但却为该过程提供了参数】。

4. 我在SQL里面写好的存储过程执行的结果也是正确的,但是为什么在VS里面调用的时候就没有结果了?

null value is eliminated by an aggregate or other SET operation
是说有null值被忽略了

SET NOCOUNT ON 的作用是比如我们执行个update,会返回多少行被修改,设置这个以后,就不返回这个信息了。这是减少存储过程不必要的开销的方式

所以目前的状况原因肯定不是SET NOCOUNT ON的问题

5. sqlserver中创建的存储过程,存储过程中定义的output参数在执行时提示错误???

--给NUMB加上默认参数就可以不用代参数执行存储过程了,这样:
create procedure pr_output 
@numb nvarchar(20)=N'' OUTPUT
AS
BEGIN
SET @NUMB='ZHANGSAN'
END
GO
EXEC pr_output
但是,你这个过程不带参数,起什么作用呢?所以,还是带参数才能得到输出结果。这样:
DECLARE @NUMB VARCHAR(10)
EXEC pr_output @NUMB OUTPUT
SELECT @NUMB

sqlserver中创建的存储过程,存储过程中定义的output参数在执行时提示错误???

6. 数据库明明有该存储过程,调用的时候就说不存在该存储过程

1、看看你的存储过程,在你的数据库中是否存在?
2、你strConn连接字符串的数据库是不是和你存储过程所在的数据库不一致?

7. 在SQL中存储过程的一般语法是什么?

1、 创建语法

create proc | procedure pro_name
[{@参数数据类型} [=默认值] [output],
{@参数数据类型} [=默认值] [output],
....
]
as
SQL_statements
2、 创建不带参数存储过程
--创建存储过程
if (exists (select * from sys.objects where name = 'proc_get_student'))
drop proc proc_get_student
go
create proc proc_get_student
as
select * from student;
--调用、执行存储过程
exec proc_get_student;
3、 修改存储过程
--修改存储过程
alter proc proc_get_student
as
select * from student;
4、 带参存储过程
--带参存储过程
if (object_id('proc_find_stu', 'P') is not null)
drop proc proc_find_stu
go
create proc proc_find_stu(@startId int, @endId int)
as
select * from student where id between @startId and @endId
go
exec proc_find_stu 2, 4;
5、 带通配符参数存储过程
--带通配符参数存储过程
if (object_id('proc_findStudentByName', 'P') is not null)
drop proc proc_findStudentByName
go
create proc proc_findStudentByName(@name varchar(20) = '%j%', @nextName varchar(20) = '%')
as
select * from student where name like @name and name like @nextName;
go
exec proc_findStudentByName;exec proc_findStudentByName '%o%', 't%';

扩展资料:
SQL存储过程优点:
1、重复使用。存储过程可以重复使用,从而可以减少数据库开发人员的工作量。
2、减少网络流量。存储过程位于服务器上,调用的时候只需要传递存储过程的名称以及参数就可以了,因此降低了网络传输的数据量。
3、安全性。参数化的存储过程可以防止SQL注入式攻击,而且可以将Grant、Deny以及Revoke权限应用于存储过程。
参考资料来源:百度百科—存储过程

在SQL中存储过程的一般语法是什么?

8. 在PL/SQL中使用SQL窗体执行存储过程的语法怎么写?(两个参数)

call Proc_name(parameter1,parameter2);


红线是说明你这个命令使用不正确。


在命令窗口中,前面加上Declare声明下就可以了
最新文章
热门文章
推荐阅读