我有一个sqlserver中写的存储过程,现在要将它转到oracle上来,不知道如何修改啊!请高手帮帮小女子啊!
根据条件取数据集:
CREATE PROCEDURE [dbo].[UserInfo_Get]
@UserID nvarchar(3),
@UserName nvarchar(20)
AS
declare @sql as nvarchar(2000)
begin
set @sql='select * from Users where 1 = 1 '+
case @UserName when '' then '' else ' and UserName = '''+@UserName+'''' end +
case @UserID when '' then '' else ' and UserID = '''+@UserID+'''' end
execute(@sql)
end问题补充:
是的,我是要返回游标。。。
可是不知道怎么写啊。。
你这个写成存储过程有什么用的? 检索了一些数据出来,你应该是要返回这些数据吧?应该要写个函数返回游标吧
-- 先创建一个自定义类型
create or replace package types as
type cur_type is ref cursor;
end;
-- 返回游标的函数
CREATE OR REPLACE FUNCTION f_test(
in_userId VARCHAR2 ,
in_userName VARCHAR2 )
RETURN types.cur_type
AS
v_cursor types.cur_type;
v_sql VARCHAR2(2000);
BEGIN
v_sql := 'select * from Users where 1 = 1';
IF in_userName IS NOT NULL THEN
v_sql := v_sql||'and UserName = '''||in_userName||'''';
END IF;
IF in_userId IS NOT NULL THEN
v_sql := v_sql||'and UserID = '''||in_userId||'''';
END IF;
OPEN v_cursor FOR
v_sql;
RETURN v_cursor;
END f_test;
根据条件取数据集:
CREATE PROCEDURE [dbo].[UserInfo_Get]
@UserID nvarchar(3),
@UserName nvarchar(20)
AS
declare @sql as nvarchar(2000)
begin
set @sql='select * from Users where 1 = 1 '+
case @UserName when '' then '' else ' and UserName = '''+@UserName+'''' end +
case @UserID when '' then '' else ' and UserID = '''+@UserID+'''' end
execute(@sql)
end问题补充:
是的,我是要返回游标。。。
可是不知道怎么写啊。。
你这个写成存储过程有什么用的? 检索了一些数据出来,你应该是要返回这些数据吧?应该要写个函数返回游标吧
-- 先创建一个自定义类型
create or replace package types as
type cur_type is ref cursor;
end;
-- 返回游标的函数
CREATE OR REPLACE FUNCTION f_test(
in_userId VARCHAR2 ,
in_userName VARCHAR2 )
RETURN types.cur_type
AS
v_cursor types.cur_type;
v_sql VARCHAR2(2000);
BEGIN
v_sql := 'select * from Users where 1 = 1';
IF in_userName IS NOT NULL THEN
v_sql := v_sql||'and UserName = '''||in_userName||'''';
END IF;
IF in_userId IS NOT NULL THEN
v_sql := v_sql||'and UserID = '''||in_userId||'''';
END IF;
OPEN v_cursor FOR
v_sql;
RETURN v_cursor;
END f_test;