自动进程的存储过程

CREATE OR REPLACE PROCEDURE QUEUE_READ_FIRST_ITEM_QNAME( P_RESULTSET OUT SYS_REFCURSOR, QUEUENAME IN VARCHAR)
IS
SPNR_ID VARCHAR(20);
QUEUE_ID INT;
QUEUE_NAME VARCHAR(40);
BEGIN
SELECT SPNRID, QUEUEID, NAME
INTO SPNR_ID, QUEUE_ID, QUEUE_NAME
FROM (
SELECT QUEUEITEMS.SPNRID, QUEUES.QUEUEID, QUEUES.NAME
FROM HX_xrezagent.QUEUEITEMS
INNER JOIN QUEUES ON QUEUES.QUEUEID=QUEUEITEMS.QUEUEID
WHERE QUEUES.NAME = QUEUENAME AND QUEUES.ACTIVE = 1 AND ACCESSED < (OJ_TIMESTAMP() - interval '10' minute) AND CREATED <= OJ_TIMESTAMP()
ORDER BY URGENT DESC, CREATED ASC)
WHERE ROWNUM = 1;
UPDATE QUEUEITEMS SET ACCESSED = OJ_TIMESTAMP WHERE QUEUEID = QUEUE_ID AND SPNRID = SPNR_ID;
OPEN P_RESULTSET FOR SELECT SPNR_ID SPNRID, QUEUE_ID QUEUEID, QUEUE_NAME NAME FROM DUAL;
EXCEPTION
WHEN no_data_found
THEN
OPEN P_RESULTSET FOR SELECT * FROM DUAL WHERE 1 = 2;
END QUEUE_READ_FIRST_ITEM_QNAME;

posted on 2019-06-02 10:14  坚守梦想  阅读(213)  评论(0编辑  收藏  举报