【问题标题】:ORACLE-SQL: stored procedure using array as parameter for selectORACLE-SQL:使用数组作为选择参数的存储过程
【发布时间】:2013-10-08 16:42:47
【问题描述】:

我必须在我的存储过程中使用一个数组。 所以我创建了一个类型变量:

CREATE OR REPLACE TYPE integer_array is table of number;

然后我尝试编写我的存储过程,但我无法编译它:

create or replace
PROCEDURE SP_TEST(
      i_id_profiles in integer_array, 
      o_clients OUT SYS_REFCURSOR
   )
AS
BEGIN
open o_clients for 
    FOR i IN 1..i_id_profiles.count LOOP
      select a.id_client from b_client a, i_client_profile b where a.id_client = b.id_client 
      and b.id_profile = i_id_profiles(i);
    END LOOP;
END SP_TEST;

你能帮帮我吗?我想获得我选择的 SYS_REFCURSOR。

谢谢

错误:

PLS-00103:在期待其中一个时遇到符号“FOR” 以下:( - + case mod new not null select with
continue avg count current exists max min prior sql stddev sum variance 执行 forall 合并时间时间戳 间隔日期管道

PLS-00103:在期待其中之一时遇到符号“文件结尾” 以下内容: end not pragma final 可实例化的顺序覆盖 静态成员构造函数映射

【问题讨论】:

  • 编译错误是什么?
  • 我现在添加编译错误,但我认为存储过程完全错误。

标签: sql oracle stored-procedures plsql


【解决方案1】:

您为查询(静态或动态)打开引用游标,您不能为for loop 构造或任何类型的循环构造打开引用游标。它只是在语义上不正确。 此外,在这种情况下,根本不需要任何类型的循环。当您将 integer_array 创建为 sql 类型(模式对象)时,您可以使用 table 运算符简单地从该类型的实例中进行选择(将其表示为表)。所以你的程序可能如下所示:

create or replace PROCEDURE SP_TEST(
      i_id_profiles in integer_array, 
      o_clients OUT SYS_REFCURSOR
   )
AS
BEGIN
  open o_clients for 
      select a.id_client 
         from b_client a 
         join i_client_profile b 
           on (a.id_client = b.id_client)
         join table(i_id_profiles)  s
           on b.id_profile = s.column_value;
END SP_TEST;  

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-11
    • 2017-05-24
    • 2012-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多