CREATE FUNCTION "FAS" . "GET_EFFECTIVE_USER_ID"
( "A_USER_ID"
BIGINT
)
RETURNS
TABLE ( "ID" BIGINT ) --注意返回的为table(col1,col2,col3) 括号里返回的表列,要一一对应
SPECIFIC "SQL131104183947721" --唯一值
LANGUAGE SQL
DETERMINISTIC
NO
EXTERNAL ACTION
READS SQL DATA
CALLED ON
NULL
INPUT
INHERIT ISOLATION
LEVEL WITHOUT LOCK REQUEST
INHERIT SPECIAL REGISTERS
RETURN --直接返回,返回的为之后查询的结果集
SELECT
CASE
WHEN
(CURR_ROLE_ID = 2 OR
CURR_ROLE_ID = 7) AND
USER_ID <> A_USER_ID
THEN
0
ELSE
USER_ID
END
ID
FROM
( SELECT A.ID USER_ID, B.ROLE_ID, C.ROLE_ID CURR_ROLE_ID
FROM
FA_USER_INFO A,
FA_USER_ROLE B,
( SELECT
ROLE_ID
FROM
FA_USER_ROLE
WHERE
USER_ID = A_USER_ID) C
WHERE
A.DEPARTMENT_ID IN
(
SELECT
DEPARTMENT_ID
FROM
FA_DEPARTMENT A, FA_DEPARTMENT_INFO B
WHERE
A.ID = B.DEPARTMENT_ID
AND
B.PARENT_DEPARTMENT_ID = ( SELECT
DEPARTMENT_ID
FROM
FA_USER_INFO
WHERE
ID = A_USER_ID)
UNION
SELECT
DEPARTMENT_ID
FROM
FA_USER_INFO
WHERE
ID = A_USER_ID)
AND
A.ID = B.USER_ID)
END ; --结束标记
|