Oracle中的过程转换

问题描述 投票:0回答:1

我是这里的新成员,如果我不能遵守这里的规则,请向我道歉。我正在使用Oracle 11g express版本和pl / sql。我试图在oracle 11g中转换sql server的数据库。到目前为止,我已经做了一切。但现在我想转换procedures。我做了所有改变,但我仍然无法完成程序。

这是SQL server中的过程代码:

create proc Result_proc 
@name varchar(40),
@Test varchar(40)
as
(
select * from [Result View] where ([Student Name] = @name AND Test# IN (@Test)) 
)

ORACLE中的转换代码:

create or replace procedure Result_proc ( 
p_name varchar2,
p_Test varchar2)
as
begin
(
select * from ahmad where (Student_Name = p_name AND Test# IN (p_Test)) 
)
end;

在您在PL / SQL中运行转换后的代码时看到的图像中,它没有正确执行:Output of CONVERTED proc in PL/SQL

输出:

SQL> 10
oracle stored-procedures plsql oracle11g
1个回答
0
投票

在SQL Server中,此存储过程意味着“将此select语句的结果返回给客户端”。在MSSQL中返回记录集的常用方法。

使用Oracle时,默认的方法是使用ref cursor输出参数。此过程应转换为类似的

create procedure Result_Proc(p_Name varchar2, p_Test varchar2, p_Result out sys_refcursor) is
begin
  open p_result for
    select * from "Result View" where student_name = p_Name and test# = p_Test;
end;

但通常更好的方法是放弃这样的垃圾程序。与MSSQL不同,Oracle不需要这样的选择SP作为安全性调用。更强大,更方便的方法是直接选择您需要的东西。

© www.soinside.com 2019 - 2024. All rights reserved.