Query on PL/SQL logic [message #434178] |
Mon, 07 December 2009 10:16 |
astik.mondal
Messages: 14 Registered: March 2008 Location: Kolkata
|
Junior Member |
|
|
Hi All,
I have written a procedure and passing a user name and multiple roles through parameters. Role parameter is varray type. Now we are fetching all the existing roles for the user using the below query:
select role_app.role_name
from dba_role_privs role_privs, role_app_tab role_app
where role_privs.granted_role = role_app.role_name
and role_privs.grantee = <user name>
and role_app.application_name = <application_name>
Now we need to implement logic where we will compare the new roles( passing as a parameter, multiple rols(array))with the existing roles (fetched by above query(loop)).
If roles are changed, means if new roles doesn't match with the existing roles, we need to revoke all the existing roles and assign the new roles(passing by parameter) to the user.
Can you please let me know how I can implement this logic?
Attaching the procedure which I have written.
Thanks,
Astik
|
|
|
|
|
|
Re: Query on PL/SQL logic [message #434243 is a reply to message #434184] |
Tue, 08 December 2009 01:55 |
astik.mondal
Messages: 14 Registered: March 2008 Location: Kolkata
|
Junior Member |
|
|
Thanks Michel for your answer.
Can I use 'Multiset Intersection' to find the differences?
Will you please give some hints how I can find the differences.
Thanks,
Astik
|
|
|
|
|
Re: Query on PL/SQL logic [message #434258 is a reply to message #434250] |
Tue, 08 December 2009 03:28 |
astik.mondal
Messages: 14 Registered: March 2008 Location: Kolkata
|
Junior Member |
|
|
Hi Michel,
As per the requirement I have changed the code below:
CREATE TYPE roleArrayType AS VARRAY(100) OF VARCHAR2(100);
/
declare
v1 rolearraytype := rolearraytype('a','b','c','d','e');
v2 rolearraytype := rolearraytype('a','c','e');
v3 rolearraytype;
begin
v3 := v2 multiset except v1;
for i in v3.FIRST .. v3.LAST
loop
dbms_output.put_line(v3(i));
end loop;
end;
But It is not working. I am getting the below error:
ORA-06550: line 6, column 7: PLS-00306: wrong number or types of arguments in call to 'MULTISET_EXCEPT_ALL' ORA-06550: line 6, column 1: PL/SQL: Statement ignored.
Any input on this would be highly appreciated.
Thanks,
Astik
|
|
|
|
|
Re: Query on PL/SQL logic [message #434262 is a reply to message #434261] |
Tue, 08 December 2009 03:44 |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
That statement makes no sense. VARRAY are not a special type of collection that can handle varchars.
Just replace Michels table with:create or replace type varchar2_tab is table of varchar2(100);
/ (alter the data length according to your requirements).
|
|
|
Re: Query on PL/SQL logic [message #434263 is a reply to message #434261] |
Tue, 08 December 2009 03:50 |
|
ramoradba
Messages: 2457 Registered: January 2009 Location: AndhraPradesh,Hyderabad,I...
|
Senior Member |
|
|
Michel And Jrowbottom already suggested....
1* create or replace type integer_tab2 is table of varchar2(1000);
SQL> /
Type created.
SQL> ed
Wrote file afiedt.buf
1* create or replace type integer_tab2 is table of varchar2(1000);
SQL> ed
Wrote file afiedt.buf
1 declare
2 v1 integer_tab2 := integer_tab2('Sriram','Oracle','Dba','Asktom','Michel');
3 v2 integer_tab2 := integer_tab2('Oracle','Asktom','Michel');
4 v3 integer_tab2;
5 begin
6 v3 := v1; --multiset except v2;
7 for i in 1..v3.count() loop
8 dbms_output.put_line(v3(i));
9 end loop;
10* end;
SQL> /
Sriram
Oracle
Dba
Asktom
Michel
PL/SQL procedure successfully completed.
SQL> ed
Wrote file afiedt.buf
1 declare
2 v1 integer_tab2 := integer_tab2('Sriram','Oracle','Dba','Asktom','Michel');
3 v2 integer_tab2 := integer_tab2('Oracle','Asktom','Michel');
4 v3 integer_tab2;
5 begin
6 v3 := v1 multiset except v2;
7 for i in 1..v3.count() loop
8 dbms_output.put_line(v3(i));
9 end loop;
10* end;
SQL> /
Sriram
Dba
PL/SQL procedure successfully completed.
SQL>
sriram
|
|
|
|
|
Re: Query on PL/SQL logic [message #434272 is a reply to message #434263] |
Tue, 08 December 2009 04:58 |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
ramoradba wrote on Tue, 08 December 2009 10:50
1* create or replace type integer_tab2 is table of varchar2(1000);
Failed review process. Please go back to drawing board.
|
|
|
|
|
Re: Query on PL/SQL logic [message #434277 is a reply to message #434275] |
Tue, 08 December 2009 05:36 |
|
ramoradba
Messages: 2457 Registered: January 2009 Location: AndhraPradesh,Hyderabad,I...
|
Senior Member |
|
|
Already said and included that its already suggested by Michel ....For the same thing i posted and used Michel type with different name Integer_tab2(Michel`s is integer_tab) i didn`t say like this is my own any where? then what ?..And i agree with Michel`s post,As he warned me for repeating post.Hope i am clear ! Then whats wrong here ?
sriram
[Updated on: Tue, 08 December 2009 05:37] Report message to a moderator
|
|
|
Re: Query on PL/SQL logic [message #434283 is a reply to message #434277] |
Tue, 08 December 2009 06:33 |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
@Michel's point is that it is poor practice to create a table that holds varchar2s and is called Integer_tab.
It will work, but it is very poor practice.
|
|
|