Chr☆s Kwok 的技术笔记

.NET, C#, WPF, WCF, WF, .NetCore & LINQ ... I know how it works because I know why it works ...

博客园 首页 新随笔 订阅 管理

1、自定义函数基本用法:

CREATE OR REPLACE FUNCTION ENTITY.fnGetFirstCardNo(v_PersonId IN number)
RETURN varchar2
AS
    v_CardNo varchar2(128);
BEGIN
    /*
    2024-10-24      guoshaoyue      Created
    --1-居民身份证
    --15-港澳居民身份证
    --16-居民户口簿
    --17-护照
    --18-军官证,19-文职干部证,20-士兵证
    --35-回乡证(港澳居民来往内地通行证)
    --36-台胞证(台湾居民来往大陆通行证)
    --42-外国人永久居留身份证
    --51-台湾居民居住证(台湾身份证)
    --99-其他身份证明
    */
    SELECT TO_CHAR(IDENTIFIERROOTID) || '|' || IDENTIFIER INTO v_CardNo
    FROM (
         SELECT * FROM entity.personidentifier WHERE IDENTIFIER IS NOT NULL AND IDENTIFIERROOTID IN (1,15,16,17,18,19,20,35,36,42,51,99) AND personId = v_PersonId ORDER BY IDENTIFIERROOTID
         )
    WHERE ROWNUM = 1;
    RETURN v_CardNo;
    
    EXCEPTION
      WHEN NO_DATA_FOUND THEN
        RETURN NULL;
END;
/

--用法示例:
select entity.fnGetFirstCardNo(3094) from dual;

--证件类型、证件号码
UPDATE DATA.OPMEDICALQCPATIENT t
SET t.IDENTIFIERROOTID=to_number(SUBSTR(t.FIRSTCARDNO, 1, INSTR(t.FIRSTCARDNO, '|')-1))
  , t.IDENTIFIER=SUBSTR(t.FIRSTCARDNO, INSTR(t.FIRSTCARDNO, '|')+1)
WHERE t.FIRSTCARDNO IS NOT NULL;

COMMIT;
/

2、随机函数使用(DBMS_RANDOM.VALUE):

UPDATE DATA.OPMEDICALQCCOURSE t SET t.CHECKINON=t.TREATEDON-FLOOR(DBMS_RANDOM.VALUE(1, 5))/24/60 WHERE t.CHECKINON IS NULL;
COMMIT;

3、如何授权给用户: 

GRANT EXECUTE ON ENTITY.fnGetFirstCardNo TO "DATA";
GRANT ALL ON ENTITY.fnGetFirstCardNo TO "DATA";
GRANT ALL ON ENTITY.PERSONIDENTIFIER  TO "DATA" WITH GRANT OPTION;

 

posted on 2024-10-30 16:33  Chr☆s  阅读(6)  评论(0编辑  收藏  举报