WEB开发网
开发学院数据库Oracle Sqlserver2005迁移至Oracle系列之五:角色、用户、... 阅读

Sqlserver2005迁移至Oracle系列之五:角色、用户、及权限

 2009-03-03 13:11:13 来源:WEB开发网   
核心提示: --数据库对象 if @class = 1 begin if @object_type = 'U' set @oraclepermission = case when @permission_name in ('CONTROL','ALTER&#

--数据库对象                      
        if @class = 1
        begin
            if @object_type = 'U'
                set @oraclepermission = case 
                                            when @permission_name in ('CONTROL','ALTER') then 'ALL'
                                            when @permission_name in ('INSERT','DELETE','SELECT','UPDATE') then @permission_name
                                            else null
                                        end
            else if @object_type in ('P','FN','IF','TF')
                set @oraclepermission = case 
                                            when @permission_name in ('CONTROL','ALTER') then 'ALL'
                                            when @permission_name in ('EXECUTE') then @permission_name
                                            else null
                                        end
            if @grantorrevoke = 'GRANT'
                set @exec = @grantorrevoke + @oraclepermission + ' ON DBO.' + upper(left(@object_name,30)) + ' TO ' + upper(@grantee_name) + ''
            else if @grantorrevoke = 'REVOKE'
                set @exec = @grantorrevoke + @oraclepermission + ' ON DBO.' + upper(left(@object_name,30)) + ' FROM ' + upper(@grantee_name) + ''

            if @exec <> ''
            begin
                if @grantorrevoke = 'REVOKE'
                begin
                    print replicate(char(9),1) +  'BEGIN'
                    print replicate(char(9),2) +  'VA_EXIST_PRIV := 0;'
                    if @oraclepermission = 'ALL'
                        print replicate(char(9),2) +  'SELECT COUNT(*) INTO VA_EXIST_PRIV FROM DBA_TAB_PRIVS WHERE OWNER = ''DBO'' AND TABLE_NAME = ''' + upper(left(@object_name,30)) +  ''' AND GRANTEE = ''' + upper(@grantee_name) +  ''';'
                    else
                        print replicate(char(9),2) +  'SELECT COUNT(*) INTO VA_EXIST_PRIV FROM DBA_TAB_PRIVS WHERE OWNER = ''DBO'' AND TABLE_NAME = ''' + upper(left(@object_name,30)) + ''' AND PRIVILEGE = ''' + upper(@oraclepermission) +  ''' AND GRANTEE = ''' + upper(@grantee_name) + ''';'
                    print replicate(char(9),2) +  'IF VA_EXIST_PRIV > 0 THEN '
                    print replicate(char(9),3) +  'EXECUTE IMMEDIATE (''' + @exec + ''');' + CHAR(9) + '--对象类型是: ' + @object_type
                    print replicate(char(9),2) +  'END IF;'
                    print replicate(char(9),1) +  'END;'
                end
                else if @grantorrevoke = 'GRANT'
                begin
                    print replicate(char(9),1) +  'BEGIN'
                    print replicate(char(9),2) +  'VA_EXIST_OBJ := 0;'
                    print replicate(char(9),2) +  'SELECT COUNT(*) INTO VA_EXIST_OBJ FROM DBA_OBJECTS WHERE OWNER = ''DBO'' AND OBJECT_NAME = ''' + upper(left(@object_name,30)) +  ''';'
                    print replicate(char(9),2) +  'IF VA_EXIST_OBJ > 0 THEN '
                    print replicate(char(9),3) +  'EXECUTE IMMEDIATE (''' + @exec + ''');' + CHAR(9) + '--对象类型是: ' + @object_type
                    print replicate(char(9),2) +  'END IF;'
                    print replicate(char(9),1) +  'END;'
                end
            end
        end
       
        fetch next from cr into @grantee_name,@class,@object_name,@object_type,@permission_name,@state_desc
    end
    close cr
    deallocate cr

    print replicate(char(9),1) +  ''
end

--脚本结束部分

begin
    print replicate(char(9),0) + 'END;'
    print replicate(char(9),0) + '--' + replicate('*',50) + '该脚本适用于 oracle数据库系统' + replicate('*',50)
    print replicate(char(9),0) + '--' + replicate('*',50) + '该脚本适用于 oracle数据库系统' + replicate('*',50)
end

系列文章:

Sqlserver2005迁移至Oracle系列之一:生成表(上)

Sqlserver2005迁移至Oracle系列之一:生成表(下)

Sqlserver2005迁移至Oracle系列之二:生成存储过程

Sqlserver2005迁移至Oracle系列之三:在Oracle中创建sql中的常见函数

Sqlserver2005迁移至Oracle系列之四:在Oracle中创建位或运算函数-bitor

Sqlserver2005迁移至Oracle系列之五:角色、用户、及权限

上一页  2 3 4 5 6 7 

Tags:Sqlserver 迁移 Oracle

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接