Oracle PL / SQL存储过程

时间:2012-09-18 16:00:00

标签: sql oracle sqlplus

我正在尝试为项目创建两个存储过程,但两者都会出错 表:

Member (MemberID, MembershipID, name, city.....)
RentalQueue (MovieID, DVDID, DateAdded)
DVD (DVID ID, Name..)
Rental(RentalID, MemberID, DVDID RequestDate,ShippedDate,ReturnDate)

两个存储过程描述和代码

1。)PL / SQL sp为客户的出租队列添加标题。此过程应将IN客户ID和电影标题ID以及电影在队列中的位置作为IN参数。该过程还应确保不能添加重复的标题,您需要在代码中添加一些错误处理。

Create procedure add_to_queue (customerID number, titleID number) as
v_count number;
begin
        select count(memberid,dvdid) 
        from rentalqueue 
        where memberid=customerid and dvdid=titleid;

     if v_count = 1 then
        raise_application_error(20000, 'This film is already  in the rentalqueue for 
        this user');
     else 
          execute immediate ’insert into rentalqueue          
          values(’||customerid||’,’||titleid||’,’||sysdate||’)’;
     end if;
end;

2。)PL / SQL存储过程,一旦请求发送,就从客户的租赁队列中删除标题。此过程应将IN客户ID和电影标题ID作为IN参数。

    Create procedure delete_from_queue (customerID number, titleID number) as
    v_count number;
begin
        select count(memberid,dvdid) 
        from rentalqueue 
        where memberid=customerid and dvdid=titleid;

        if v_count = 1 then
           execute immediate ’delete from rentalqueue 
           where memberid=’||customerid||’ and dvdid=’||titleid;
        else 
        raise_application_error(20000, 'This film was not in the rentalqueue for this  
        user');
       end if;
 end;

Compile ErrorI get on both下面。我知道前两个错误必须用我做的SELECT语句做一些事情,但无法弄清楚出了什么问题。

Error(4,20): PL/SQL: SQL Statement ignored
Error(4,27): PL/SQL: ORA-00909: invalid number of arguments
Error(6,41): PLS-00103: Encountered the symbol "’" when expecting one of the
    following:     ( - + case mod new not null <an identifier>    
<a double-quoted delimited-identifier> <a bind variable>    continue avg count current
 exists max min prior sql stddev    sum variance execute forall merge time timestamp 
interval    date <a string literal with character set specification>
    <a number> <a single-quoted SQL string> pipe    <an alternatively-quoted string
 literal with character set specification>    <an alternatively

1 个答案:

答案 0 :(得分:0)

这不是正确的符号 -

这是 - '

尝试编辑Toad或SQL Developer中的过程以获得更好的结果。这些IDE将使用红线突出显示任何可能的语法错误。