由于Oracle中的函数体而导致编译错误而创建的包体

时间:2017-03-05 06:40:27

标签: oracle oracle10g package

我正在使用Oracle 10g Express版。

这是我的包创建代码: -

CREATE OR REPLACE PACKAGE ticketBooking 
   AS 
      PROCEDURE bookOrder(id IN NUMBER, key IN VARCHAR2, fname IN VARCHAR2, lname IN VARCHAR2, age IN NUMBER, address IN VARCHAR2, adate IN VARCHAR2, status OUT NUMBER);
      PROCEDURE bookTicket(id IN NUMBER, orderID IN NUMBER, mID IN NUMBER, mRow IN NUMBER, mSeat IN NUMBER, mDate IN VARCHAR2, mTime IN NUMBER, status OUT NUMBER);
      FUNCTION maxOrderID RETURN NUMBER; 
      FUNCTION maxTransactionID RETURN NUMBER;
   END ticketBooking; 
/

现在,这是包体创建: -

    CREATE OR REPLACE PACKAGE BODY ticketBooking
    IS
        PROCEDURE 
        bookOrder (id IN NUMBER, key IN VARCHAR2, fname IN VARCHAR2, lname IN VARCHAR2, age IN NUMBER, address IN VARCHAR2, adate IN VARCHAR2, status OUT NUMBER) 
        IS
          BEGIN
            INSERT INTO tbl_order (order_id, order_key, order_fname, order_lname, order_age, order_address, order_add_date) 
            VALUES ( id, key, fname, lname, age, address, TO_DATE(adate, 'YYYY-MM-DD hh24:mi:ss'));
            status := 1;
          EXCEPTION
            WHEN OTHERS THEN
            status := 0;
          END bookOrder;

        PROCEDURE 
        bookTicket (id IN NUMBER, orderID IN NUMBER, mID IN NUMBER, mRow IN NUMBER, mSeat IN NUMBER, mDate IN VARCHAR2, mTime IN NUMBER, status OUT NUMBER)
        IS
          BEGIN
            INSERT INTO tbl_transaction (transaction_id, order_id, movie_id, movie_row, movie_seat, movie_date, movie_time) 
            VALUES ( id, orderID, mID, mRow, mSeat, mDate, mTime);
            status := 1;
          EXCEPTION
            WHEN OTHERS THEN
            status := 0;
          END bookTicket;

        FUNCTION 
        maxOrderID RETURN NUMBER
        IS
          mOID NUMBER:=0;
          BEGIN
            SELECT CASE WHEN MAX(order_id) > 0 THEN MAX(order_id) ELSE 0 END INTO mOID FROM tbl_order;
            return (mOID);
          END maxOrderID; 

        FUNCTION 
        maxTransactionID RETURN NUMBER 
        IS
          mTID NUMBER:=0;
          BEGIN
            SELECT CASE WHEN MAX(transaction_id) > 0 THEN MAX(transaction_id) ELSE 0 END INTO mTID FROM tbl_transaction;
            return (mTID);
          END maxTransactionID;

    END ticketBooking;
/

我收到包装体创建时出现编译错误的错误。 我究竟做错了什么? 当我删除函数时,那时没有显示警告或编译错误。

1 个答案:

答案 0 :(得分:1)

你错过了:

  • 函数的return子句。添加return number
  • {li> thenend if中的if

试试这个:

create or replace PACKAGE BODY ticketBooking
    IS
        PROCEDURE 
        bookOrder (id IN NUMBER, key IN VARCHAR2, fname IN VARCHAR2, lname IN VARCHAR2, age IN NUMBER, address IN VARCHAR2, adate IN VARCHAR2, status OUT NUMBER) 
        IS
          BEGIN
            INSERT INTO tbl_order (order_id, order_key, order_fname, order_lname, order_age, order_address, order_add_date) 
            VALUES ( id, key, fname, lname, age, address, TO_DATE(adate, 'YYYY-MM-DD hh24:mi:ss'));
            status := 1;
          EXCEPTION
            WHEN OTHERS THEN
            status := 0;
          END bookOrder;

        PROCEDURE 
        bookTicket (id IN NUMBER, orderID IN NUMBER, mID IN NUMBER, mRow IN NUMBER, mSeat IN NUMBER, mDate IN VARCHAR2, mTime IN NUMBER, status OUT NUMBER)
        IS
          BEGIN
            INSERT INTO tbl_transaction (transaction_id, order_id, movie_id, movie_row, movie_seat, movie_date, movie_time) 
            VALUES ( id, orderID, mID, mRow, mSeat, mDate, mTime);
            status := 1;
          EXCEPTION
            WHEN OTHERS THEN
            status := 0;
          END bookTicket;

        FUNCTION 
        maxOrderID return number
        IS
          mOID NUMBER:=0;
          dReturn NUMBER:=0; 
          BEGIN
            SELECT MAX(order_id) INTO mOID FROM tbl_order;
            if(mOID > 0) then
               return (mOID);
            else
               return (dReturn);   
              end if;
          END maxOrderID; 

        FUNCTION 
        maxTransactionID return number
        IS
          mTID NUMBER:=0;
          dReturn NUMBER:=0; 
          BEGIN
            SELECT MAX(transaction_id) INTO mTID FROM tbl_transaction;
            if(mTID > 0) then
               return (mTID);
            else
               return (dReturn);   
              end if;
          END maxTransactionID;

    END ticketBooking;