简体   繁体   English

从 rowtype 参数分配给变量值

[英]Assign to variables values from rowtype parameter

I've searched on stackoverflow and other sources, but haven't found anything useful.我搜索了 stackoverflow 和其他来源,但没有发现任何有用的东西。

I have to implement a procedure that receives a row (hence "%rowtype") from Reservation table as a parameter.我必须实现一个从 Reservation 表中接收一行(因此为“%rowtype”)作为参数的过程。

The table's name is Reservation (as attributes: id_Reservation, id_Room, price, etc).该表的名称是 Reservation(作为属性:id_Reservation、id_Room、price 等)。

I created an anonymous block to create the var_reservation variable, which will serve as the parameter to the procedure:我创建了一个匿名块来创建 var_reservation 变量,它将作为过程的参数:

CREATE OR REPLACE PROCEDURE priceCheckout(var_reservation reservation%ROWTYPE) IS
    l_idReservation NUMBER;
    l_idRoom NUMBER;
    prie INT;
    date1 DATE;
    date2 DATE;
    ex exception;

BEGIN
    l_idReservation := var_reservation.id_reservation;
    (...)
END;

But this is wrong.但这是错误的。 How can I correct this?我该如何纠正?

If you do it correctly , it works.如果你做对了,它就可以工作。 Have a look at the following example based on Scott's DEPT table:看看以下基于 Scott 的DEPT表的示例:

SQL> select * from dept;

    DEPTNO DNAME                LOC
---------- -------------------- --------------------
        10 ACCOUNTING           NEW YORK
        20 RESEARCH             DALLAS
        30 SALES                CHICAGO
        40 OPERATIONS           BOSTON

SQL> set serveroutput on

Procedure:程序:

SQL> create or replace procedure p_test (var_row dept%rowtype)
  2  is
  3    l_dname dept.dname%type;
  4  begin
  5    l_dname := var_row.dname;
  6
  7    dbms_output.put_line('Department name = ' || l_dname);
  8  end;
  9  /

Procedure created.

Testing:测试:

SQL> declare
  2    l_row dept%rowtype;
  3  begin
  4    select *
  5      into l_row
  6      from dept
  7      where deptno = 10;
  8
  9    p_test(l_row);
 10  end;
 11  /
Department name = ACCOUNTING

PL/SQL procedure successfully completed.

SQL>

Saying that "this is wrong" is difficult to debug.说“这是错误的”很难调试。 It is not an Oracle error message so... unless you specify what is "this" and, possibly, edit the question and post copy/paste of your own SQL*Plus session (like I did) so that we'd see what you did and how Oracle responded, YOYO.它不是 Oracle 错误消息,所以...除非您指定什么是“this”,并且可能编辑问题并发布您自己的 SQL*Plus session 的复制/粘贴(就像我所做的那样),以便我们看看你做了以及 Oracle 如何回应,YOYO。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM