0

原谅我,这是我第一次尝试 Oracle 包,所以我希望错过一些简单的东西。

编辑我对其进行了排序...需要引用实际的声明子类型,例如:

 FOR j in outvar(i).tbl_ORDER_TENDERS.first..outvar(i).tbl_ORDER_TENDERS.last LOOP
         DBMS_OUTPUT.PUT_LINE('tender record : '
         || to_char(outvar(i).tbl_ORDER_TENDERS(j).TENDER_AMT)      || ' ' 

我创建了几个新的 Oracle 类型,它们将保存我的数据库中的行数据,如下所示:

create or replace 
TYPE ORDERS_TABLE 
IS TABLE OF ORDER_HEADER;

那是指我的另一种类型:

create or replace 
TYPE ORDER_HEADER FORCE
AS OBJECT (
  TRANSACTION_NUMBER    VARCHAR2(20),
  LOCATION_NUMBER       VARCHAR2(10),
  TERMINAL_NAME         VARCHAR2(25),       
  START_DATETIME        TIMESTAMP(6),
  GROSS_SALES_AMOUNT    NUMBER(20,0),
  NET_SALES_AMOUNT      NUMBER(20,0),
  SAVINGS_AMOUNT        NUMBER(20,0),
  SAVINGS_PRECISION     NUMBER(6,0),
  TOTAL_TAX             NUMBER(20,0),
  CUSTOMER_IDENTIFIER   VARCHAR2(50),
  tbl_ORDER_LINES       ORDER_LINES,
  tbl_ORDER_TENDERS     ORDER_TENDERS,
  TBL_ORDER_REBATES     ORDER_REBATES
);

例如,采用 ORDER_TENDERS 类型:

create or replace 
TYPE ORDER_TENDERS  FORCE
AS TABLE OF ORDER_TENDER;

其中包含投标数据行:

create or replace 
TYPE ORDER_TENDER AS OBJECT 
( 
  TENDER_LINE_ID            NUMBER(20,0),
  TENDER_CODE               VARCHAR2(10),
  TENDER_AMT                NUMBER(20,0),
  UNENCODED_ACCOUNT_NUMBER  VARCHAR2(25)
);

所以我认为我的包正在工作,我可以在其中填充这些对象(至少验证了 HEADER 的东西。)但是当我调用这个包以查看我是否在时,我不确定如何测试/调试/查看结果获取 ORDER_TENDER/ORDER_TENDERS 数据...

例如,这很好用:

declare
 invar varchar2(5);
 outvar ORDERS_TABLE;
 O_ORDER_TENDERS ORDER_TENDERS;
 O_ORDER_TENDER  ORDER_TENDER;
 begin
 sales_trickler.GetSales(invar, outvar);

 FOR i in 1..outvar.COUNT LOOP 
      DBMS_OUTPUT.PUT_LINE(' record : ' 
      || to_char(outvar(i).TRANSACTION_NUMBER)      || ' '
      || to_char(outvar(i).LOCATION_NUMBER)         || ' '
      || to_char(outvar(i).TERMINAL_NAME)           || ' '
      || to_char(outvar(i).CUSTOMER_IDENTIFIER));

   END LOOP; 
end;

但是如何查看 ORDER_TENDERS/ORDER_TENDER 数据?

我尝试将这个额外的 FOR LOOP 放入,但它不喜欢我指的是 ORDER_TENDER(S)...

declare
 invar varchar2(5);
 outvar ORDERS_TABLE;
 O_ORDER_TENDERS ORDER_TENDERS;
 O_ORDER_TENDER  ORDER_TENDER;
 begin
 sales_trickler.GetSales(invar, outvar);

 FOR i in 1..outvar.COUNT LOOP 
      DBMS_OUTPUT.PUT_LINE(' record : ' 
      || to_char(outvar(i).TRANSACTION_NUMBER)      || ' '
      || to_char(outvar(i).LOCATION_NUMBER)         || ' '
      || to_char(outvar(i).TERMINAL_NAME)           || ' '
      || to_char(outvar(i).CUSTOMER_IDENTIFIER));
      FOR j in 1..outvar(i).O_ORDER_TENDERS.COUNT LOOP
      DBMS_OUTPUT.PUT_LINE('tender record : '
      || to_char(O_ORDER_TENDERS(j).TENDER_AMT)      || ' '           
      );
      END LOOP;

   END LOOP; 
end;

我尝试与 outvar(i).ORDER_TENDERS 相关,但这也没有用……有什么想法吗?

4

1 回答 1

0

问题出在调用代码中,我不应该引用子对象的新实例,我应该在传递的原始参数中“原样”引用它们,如下所示:

 tbl_ORDER_LINES       ORDER_LINES,
 tbl_ORDER_TENDERS     ORDER_TENDERS,
 TBL_ORDER_REBATES     ORDER_REBATES

这是实际的声明:

declare
 invar varchar2(5);
 outvar ORDERS_TABLE;
 begin
 sales_trickler.GetSales(invar, outvar);

 FOR i in 1..outvar.COUNT LOOP 
      DBMS_OUTPUT.PUT_LINE(' record : ' 
      || to_char(outvar(i).TRANSACTION_NUMBER)      || ' '
      || to_char(outvar(i).LOCATION_NUMBER)         || ' '
      || to_char(outvar(i).TERMINAL_NAME)           || ' '
      || to_char(outvar(i).CUSTOMER_IDENTIFIER));

       FOR j in outvar(i).tbl_ORDER_TENDERS.first..outvar(i).tbl_ORDER_TENDERS.last LOOP
         DBMS_OUTPUT.PUT_LINE('tender record : '
         || to_char(outvar(i).tbl_ORDER_TENDERS(j).TENDER_AMT)      || ' ' 

  );
  END LOOP;
  --lines
   FOR j in outvar(i).tbl_ORDER_LINES.first..outvar(i).tbl_ORDER_LINES.last LOOP
     DBMS_OUTPUT.PUT_LINE('line record : '
     || to_char(outvar(i).tbl_ORDER_LINES(j).SKU)      || ' ' 

  );
  END LOOP;

结束循环;结尾;

于 2013-09-03T15:40:57.583 回答