创建存储过程编译错误

时间:2014-12-08 12:31:49

标签: sql database oracle stored-procedures

我正在尝试在oracle中创建存储过程,但每次我尝试将其添加到数据库时都会出现错误Procedure created with compilation errors

我无法执行它(也会出错)。我想象我的实际程序有问题,但我无法弄明白。这是我试图创建的程序:

CREATE PROCEDURE SPBILL @CLIENT_ID VARCHAR2(6)
AS 
BEGIN
    SELECT C.CLIENT_NAME, B.ROOM_ID, R.ROOM_COST, T.TREAT_NAME, T.TREAT_COST, (ROOM_COST*(B_END_DATE-B_START_DATE)+TREAT_COST) AS INVOICE
    FROM CLIENTS C, ROOMS R, TREATMENTS T, BOOKING B, PRESCRIPTION P
    WHERE C.CLIENT_ID=B.CLIENT_ID
    AND R.ROOM_ID=B.ROOM_ID
    AND B.CLIENT_ID=P.CLIENT_ID
    AND P.TREAT_ID=T.TREAT_ID
    AND C.CLIENT_ID=@CLIENT_ID
END;

2 个答案:

答案 0 :(得分:0)

尝试以下

CREATE PROCEDURE SPBILL (CLIENT_ID VARCHAR2)
AS 
BEGIN
   SELECT C.CLIENT_NAME, B.ROOM_ID, R.ROOM_COST, T.TREAT_NAME, T.TREAT_COST, (ROOM_COST*(B_END_DATE-B_START_DATE)+TREAT_COST) AS INVOICE
   FROM CLIENTS C, ROOMS R, TREATMENTS T, BOOKING B, PRESCRIPTION P
   WHERE C.CLIENT_ID=B.CLIENT_ID
   AND R.ROOM_ID=B.ROOM_ID
   AND B.CLIENT_ID=P.CLIENT_ID
   AND P.TREAT_ID=T.TREAT_ID
   AND C.CLIENT_ID= CLIENT_ID 
END;

答案 1 :(得分:0)

这一定非常愚蠢,但我认为它是你声明变量@CLIENT_ID

的方式

您是否尝试过像这样DELCARE @CLIENT_ID VARCHAR2(6)声明变量?

请查看此链接How to use local variables in stored procedures?