Oracle函数在程序中使用自动递增

时间:2016-03-04 19:04:00

标签: function stored-procedures oracle10g

我有表名渲染,我为它创建了一个程序。 我的桌子是

 CREATE TABLE ROOM(
 ROOM_ID NUMBER(10) NOT NULL,
 ROOM_NO NUMBER(10) NOT NULL,
 ROOM_DETAILS VARCHAR2(100) NOT NULL,
 PRICE NUMBER(30) NOT NULL,
 ROOM_PACKAGE VARCHAR2(100) NOT NULL
);

程序是

CREATE OR REPLACE PROCEDURE P_ROOM(
    p_room_id IN ROOM.ROOM_ID%TYPE,
    p_room_no IN ROOM.ROOM_NO%TYPE,
    p_room_details IN ROOM.ROOM_DETAILS%TYPE,
    p_price IN ROOM.PRICE%TYPE,
    p_room_package IN ROOM.ROOM_PACKAGE%TYPE)
 IS
BEGIN
INSERT INTO ROOM("ROOM_ID","ROOM_NO","ROOM_DETAILS","PRICE","ROOM_PACKAGE")
VALUES(p_room_id,p_room_no,p_room_details,p_price,p_room_package);
COMMIT;
END;    
/

但我想创建一个函数,它将调用过程并将用于增加ROOM_ID。我如何创建这样做的功能? 我正在尝试创建一个函数,但实际上我不能

CREATE OR REPLACE FUNCTION AUTO_GEN
ID IN ROOM.ROOM_ID%TYPE
RETURN NUMBER
BEGIN
F_ID NUMBER(5);
F_ID=SELECT MAX(ROOM_ID) FROM ROOM;
 IF(ROOM_ID NULL) THEN
    ID=0;
  ELSE
    ID=ROOM_ID+1;
END IF;
RETURN ID;
END;
/

0 个答案:

没有答案