修改“在子程序里声明变量和常量并赋值”章节示例中 p_name 的类型,使用 ware.w_name%type 代替 varchar。

    1. delimiter /
    2. CREATE OR REPLACE PACKAGE pkg_ware_mgmt as
    3. MAX_WARES constant number(2,0) := 10;
    4. MAX_DISTS_PER_WARE constant number(2,0) := 10;
    5. FUNCTION f_check_ware_exists(p_name IN ware.w_name%TYPE) RETURN BOOLEAN ;
    6. END;
    7. /
    8. delimiter ;
    9. delimiter /
    10. CREATE OR REPLACE PACKAGE BODY pkg_ware_mgmt as
    11. FUNCTION f_check_ware_exists( p_name IN ware.w_name%TYPE ) RETURN BOOLEAN
    12. IS
    13. i_cnt number := -1;
    14. b_ret boolean := FALSE;
    15. BEGIN
    16. SELECT count(*) INTO i_cnt FROM ware WHERE w_name = p_name AND rownum < 2;
    17. b_ret := (i_cnt = 1);
    18. RETURN b_ret;
    19. EXCEPTION
    20. WHEN OTHERS THEN
    21. RETURN FALSE;
    22. END;
    23. END;
    24. /
    25. delimiter ;
    26. obclient>