1

I am required to use an explicit cursor with a parameter that accepts car registration to find the most recent reservation made on the car. I cannot use the MAX function. I have to compare all the relevant dates to find the most recent one.

This is what I have so far"

Declare
  v_rec_date DATE; 
    Cursor date_cur (v_reg VARCHAR2) IS 
    SELECT * FROM i_booking
    WHERE registration = v_reg;
    v_date date_cur%ROWTYPE;
  Begin
   FOR v_date IN date_cur LOOP 
     DBMS_OUTPUT.PUT_LINE('Recent Rental Date:'|| ' '||v_rec_date); 
   END LOOP;
  End;

However this is giving me the error:

FOR v_date IN date_cur LOOP
              *
ERROR at line 8: 
ORA-06550: line 8, column 15: 
PLS-00306: wrong number or types of arguments in call to 'DATE_CUR' 
ORA-06550: line 8, column 1: 
PL/SQL: Statement ignored 

Where am I going wrong here?

4

1 回答 1

1

您已经创建了一个参数化游标,但您没有传递任何参数。

当此行执行时: FOR v_date IN date_cur LOOP

您需要为 v_reg 传递一个值,因为这就是您设计光标的方式。

在此处查看 Oracle 文档以获取示例。

具体看一下链接中标题为“示例 6-20 将参数传递给显式游标 FOR LOOP 语句”的部分,他们在其中所做的几乎与您在此处尝试的一样。

当您声明像这里这样的游标时:Cursor date_cur (v_reg VARCHAR2)您是说当您打开此游标时,您会将引用为 v_reg 的参数传递给游标,并且 v_reg 将是 VARCHAR2 类型。

然后,当您尝试在此处使用光标时:FOR v_date IN date_cur LOOP 您收到的错误基本上是:“您承诺在打开光标 date_cur 时包含一个参数,但您没有给我一个参数。”

这是您所拥有的,但现在将一个参数传递给游标。

   Declare
  v_rec_date DATE; 
    Cursor date_cur (v_reg VARCHAR2) IS 
    SELECT * FROM i_booking
    WHERE registration = v_reg;
    v_date date_cur%ROWTYPE;
  Begin
   FOR v_date IN date_cur("SOME VALUE HERE") LOOP 
     DBMS_OUTPUT.PUT_LINE('Recent Rental Date:'|| ' '||v_rec_date); 
   END LOOP;
  End;
于 2013-10-17T02:56:00.183 回答