oracle创建存储过程和函数的简单例子

获取32位UUID的存储函数:

CREATE OR REPLACE FUNCTION get_uuid 
RETURN VARCHAR
IS
guid VARCHAR (32);
BEGIN
guid := lower(RAWTOHEX(sys_guid()));
RETURN substr(guid,0,8)||substr(guid,9,13)||substr(guid,14,15);
END get_uuid;

带输入参数的简单存储过程:

CREATE OR REPLACE PROCEDURE scan_list_pro
 (forward_day in VARCHAR2) AS
BEGIN
    DECLARE shipCode VARCHAR2(13);
        BEGIN

            SELECT ship_code INTO shipCode FROM TAB_SHIP  where TRANSPORT_STATUS in ('PAYBACK', 'PAY') 
                and trunc(sysdate, 'dd') - trunc(edit_time,'dd') >= forward_day;

            INSERT INTO TAB_SCAN_LIST_LEO(SHIP_CODE) VALUES(shipCode);  
        END;

END scan_list_pro;

带输出参数的简单存储过程:

CREATE OR REPLACE PROCEDURE gain_datas 
(re_value out VARCHAR2) AS 
BEGIN
    DECLARE temp_date DATE;
    BEGIN 
        temp_date := '';
        re_value := 'SELECT sysdate into temp_date FROM dual';
    end;

END gain_datas;

你可能感兴趣的:(oracle创建存储过程和函数的简单例子)