带in和multi out参数错误的oracle sql过程

wlwcrazw  于 2021-08-13  发布在  Java
关注(0)|答案(1)|浏览(363)

我创建了一个过程来获取多个out参数。但是编译错误来了。我找不到问题。请,我需要一些支持来找到这个问题。。。。。。。。。。。。。
我的密码是,
基本数据库客户、预订和服务表如下所示,

CREATE TABLE CUSTOMER
       (CUSTOMER_ID NUMBER(4) NOT NULL,
        CUSTOMER_NAME VARCHAR2(10),
        GENDER VARCHAR(10),
        ADDRESS VARCHAR(50),
        EMAIL VARCHAR(50),
        DISCOUNT FLOAT(10),
        PRIMARY KEY(CUSTOMER_ID)
        );

CREATE TABLE SERVICE
        (SERVICE_ID NUMBER(4) NOT NULL,
        SERVICE_NAME VARCHAR(100),
        CHARGE FLOAT(10),   
        PRIMARY KEY(SERVICE_ID)             
        );

CREATE TABLE RESERVATION
        (RESERVATION_ID NUMBER(4) NOT NULL,
        RESERVATION_DATE DATE,
        CUSTOMER_ID NUMBER(4),
        SERVICE_ID NUMBER(4),
        EMPLOYEE_ID NUMBER(4),
        PRIMARY KEY(RESERVATION_ID),
        FOREIGN KEY (CUSTOMER_ID) REFERENCES CUSTOMER(CUSTOMER_ID),
        FOREIGN KEY (SERVICE_ID) REFERENCES SERVICE(SERVICE_ID),
        FOREIGN KEY (EMPLOYEE_ID) REFERENCES EMPLOYEE(EMPLOYEE_ID)              
        );

我需要从预订台、服务台和顾客台取些淡水。我的程序如下,

SET SERVEROUTPUT ON
CREATE OR REPLACE PROCEDURE GET_RECEIPT(
    RES_ID IN RESERVATION.RESERVATION_ID%TYPE,
    C_NAME OUT CUSTOMER.CUSTOMER_NAME%TYPE,
    S_NAME OUT SERVICE.SERVICE_NAME%TYPE,
    CHARGE_VAL OUT FLOAT(10),
    DISCOUNT_VAL OUT FLOAT(10),
    TOTAL_VAL OUT FLOAT(10)
    ) 
AS
BEGIN
    SELECT 
        c.CUSTOMER_NAME AS CUS_NAME INTO C_NAME,
        s.SERVICE_NAME AS SER_NAME INTO S_NAME,
        s.CHARGE AS CHAR_VAL INTO CHARGE_VAL,
        c.DISCOUNT INTO DISCOUNT_VAL,
        (s.CHARGE-c.DISCOUNT)AS TOTAL INTO TOTAL_VAL 
    FROM RESERVATION r LEFT OUTER JOIN CUSTOMER c ON r.CUSTOMER_ID=c.CUSTOMER_ID LEFT OUTER JOIN SERVICE s ON r.SERVICE_ID=s.SERVICE_ID 
    WHERE r.RESERVATION_ID=RES_ID;  
END;
/

但是这个过程无法编译。它说编译失败了。我怎样才能解决这个问题?

yvt65v4c

yvt65v4c1#

修正了,看起来是这样的:

SQL> create or replace procedure get_receipt(
  2      res_id in reservation.reservation_id%type,
  3      c_name out customer.customer_name%type,
  4      s_name out service.service_name%type,
  5      charge_val out float,
  6      discount_val out float,
  7      total_val out float
  8      )
  9  as
 10  begin
 11      select c.customer_name, s.service_name, s.charge, c.discount, s.charge - c.discount
 12      into c_name, s_name, charge_val, discount_val, total_val
 13      from reservation r left outer join customer c on r.customer_id=c.customer_id
 14      left outer join service s on r.service_id=s.service_id
 15      where r.reservation_id=res_id;
 16  end;
 17  /

Procedure created.

SQL>

你做错什么了?
参数没有大小(不是 float(10) 但只是 float )
在pl/sql中, select 必须有 into 条款-这是你所做的,但在一个错误的方式。应该和我的例子一样。

相关问题