Oracle personnel permissions, string-to-column conversion, statistical management details, oracle details

Source: Internet
Author: User

Oracle personnel permissions, string-to-column conversion, statistical management details, oracle details

Use table Valued Functions

1. Create a type

Create or replace type row_sys_user as object (

Userid int,

Roleid varchar2 (500)

)

2. Create a table

Create or replace type tabemp as table of row_sys_user

3. Create a table Value Function

Create or replace function strsplit1 (p_value1 varchar2,

P_split1 varchar2: = ',')

-- Usage: select * from table (strsplit ('1, 2, 3, 4, 5 '))

Return tabemp

Pipelined is

V_idx integer;

V_userid integer;

V_strs_last varchar2 (4000 );

V_str varchar2 (500 );

V row_sys_user;

Cursor temp is

Select id, roleids from sys_user;

Begin

Open temp;

Loop

Fetch temp into v_userid, v_strs_last;

Exit when temp % notfound;

Loop

V_idx: = instr (v_strs_last ,',');

Exit when v_idx = 0;

V_str: = substr (v_strs_last, 1, v_idx-1 );

V_strs_last: = substr (v_strs_last, v_idx + 1 );

V: = row_sys_user (v_userid, v_str );

Pipe row (v );

End loop;

V: = row_sys_user (v_userid, v_strs_last );

Pipe row (v );

End loop;

Close temp;

Return;

End strsplit1;

4. Obtain the permissions of the old version of the system

Select c. name orgname, d. name deptname, a. realname, B. name

From sys_user a, sys_role B, sys_org c, sys_org d, table (strsplit1 ('','') e

Where a. id = e. userid and B. id = e. roleid

And a. orgid = c. id and a. deptid = d. id

And c. ext4 in ('20140901', '20160901 ')

Order by c. name, d. name, a. realname, B. name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.