写一个存储过程,输入表名然后显示表中的数据。 5
createorreplaceprocedureshow_data(tablenameinvarchar(50))asbeginexecuteimmediate'sele...
create or replace procedure show_data
(
tablename in varchar(50)
)
as
begin
execute immediate 'select * from '+tablename;
end;
/
怎么是错的 展开
(
tablename in varchar(50)
)
as
begin
execute immediate 'select * from '+tablename;
end;
/
怎么是错的 展开
2个回答
展开全部
额
CREATE PROCEDURE P_TEST(
@tableName VARCHAR(50) --查询的表名
)
AS
BEGIN
DECLARE @strSQL VARCHAR(1000)
IF NOT EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = Object_Id(N'' + @tableName + '') AND OBJECTPROPERTY(ID, N'IsUserTable') = 1)
BEGIN
SELECT 0
RETURN
END
SELECT @strSQL = 'SELECT * FROM ' + @tableName
EXEC(@strSQL)
END
执行P_TEST 表名
CREATE PROCEDURE P_TEST(
@tableName VARCHAR(50) --查询的表名
)
AS
BEGIN
DECLARE @strSQL VARCHAR(1000)
IF NOT EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = Object_Id(N'' + @tableName + '') AND OBJECTPROPERTY(ID, N'IsUserTable') = 1)
BEGIN
SELECT 0
RETURN
END
SELECT @strSQL = 'SELECT * FROM ' + @tableName
EXEC(@strSQL)
END
执行P_TEST 表名
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
CREATE PROC showData(@tableName nvarchar(50))
AS
BEGIN
EXEC('SELECT * FROM ' + @tableName)
END
AS
BEGIN
EXEC('SELECT * FROM ' + @tableName)
END
追问
create or replace procedure show_data
(
tablename in varchar(50),
)
as
begin
execute immediate 'select * from '+tablename;
end;
/
为什么是错的啊
追答
create or replace procedure show_data
(
@tablename in varchar(50), --变量要有 @
)
as
begin
execute immediate 'select * from ' + @tablename;
end;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询