标签:grant current 行修改 admin creat int var 延伸 sel
SAP HANA中的用户是没有功能进行直接的拷贝的,但是我们可以通过建立存储过程调用,通过sql语句的方式进行拷贝:
存储过程定义如下,各位可根据自己的需求进行修改:
CREATE PROCEDURE SYSTEM.COPY_USER (IN V_SOURCE_USER NVARCHAR(256), IN V_TARGET_USER NVARCHAR(256), IN V_TARGET_PWD NVARCHAR(256)) LANGUAGE SQLSCRIPT AS
V_FOUND INT := 1;
CURSOR C_ROLE_LIST (V_SRC_USER NVARCHAR(256)) FOR
SELECT ROLE_NAME, IS_GRANTABLE FROM "SYS"."GRANTED_ROLES" WHERE GRANTEE=:V_SRC_USER AND GRANTEE_TYPE=‘USER‘ AND GRANTOR=CURRENT_USER;
BEGIN
SELECT COUNT(*) INTO V_FOUND FROM "SYS"."USERS" WHERE USER_NAME = :V_SOURCE_USER;
IF :V_FOUND = 1 THEN
EXEC ‘CREATE USER ‘ || :V_TARGET_USER || ‘ PASSWORD ‘ || :V_TARGET_PWD;
FOR V_LIST_ROW AS C_ROLE_LIST(:V_SOURCE_USER) DO
IF V_LIST_ROW.IS_GRANTABLE=‘FALSE‘ THEN
EXEC ‘GRANT ‘ || V_LIST_ROW.ROLE_NAME || ‘ TO ‘ || :V_TARGET_USER;
ELSE
EXEC ‘GRANT ‘ || V_LIST_ROW.ROLE_NAME || ‘ TO ‘ || :V_TARGET_USER || ‘ WITH ADMIN OPTION‘;
END IF;
END FOR;
END IF;
END;
调用方式如下:
CALL SYSTEM.COPY_USER (‘SYSTEM‘, ‘Ivan‘, ‘Initial1‘);
CALL COPY_USER (‘SOURCE_USER‘, ‘TARGET_USER‘, ‘INITIAL_PASSWORD‘)
在密码参数设置的时候,注意密码最短长度为8位,需要大小写和数据混合密码。
根据这个存储过程的使用方法,我们可以延伸出角色拷贝等多种应用场景!
标签:grant current 行修改 admin creat int var 延伸 sel
原文地址:http://www.cnblogs.com/lan-meng/p/5986739.html