Reputation: 569
My simple sql statement is this:
SELECT USERNAME FROM ALL_USERS;
But I want to filter system users from the result. I searched but couldn't find anything that Oracle provided; so I tried a statement like this and it doesn't work:
select username from all_users where username not like '%SH%'
or username not like '%SYS%'
or username not in ('ANONYMOUS',
'DBSNMP',
'MGMT_VIEW',
'ORDPLUGINS',
'OUTLN',
'SI_INFORMATION_SCHEMA',
'WK_TEST',
'WKPROXY',
'XDB');
This doesn't work. How should I modify my query for the desired output or maybe there is something oracle provides to get predefined system accounts?
Upvotes: 4
Views: 1769
Reputation: 57656
You can try this:
select username from all_users where username not like '%SH%'
AND username not like '%SYS%'
INTERSECT
select username from all_users where username not in ('ANONYMOUS',
'DBSNMP',
'MGMT_VIEW',
'ORDPLUGINS',
'OUTLN',
'SI_INFORMATION_SCHEMA',
'WK_TEST',
'WKPROXY',
'XDB');
Upvotes: 0
Reputation:
A slight twist on the other answers: not (A or B or C) = not A and not B and not C, so what you probably originally wanted was:
select username from all_users
where not (username like '%SH%'
or username like '%SYS%'
or username in ('ANONYMOUS',
'DBSNMP',
'MGMT_VIEW',
'ORDPLUGINS',
'OUTLN',
'SI_INFORMATION_SCHEMA',
'WK_TEST',
'WKPROXY',
'XDB')
);
Upvotes: 5
Reputation: 7116
replace or
with AND
, I think it will start working.
However a better approach might be to have a flag indicating whether its a system user or not. A more sophosticated approach might be to have seperate table for rights that will have many to many relationship with User table.
Upvotes: 2
Reputation: 270609
Instead of OR
, you will need to use AND
select username from all_users where username not like '%SH%'
AND username not like '%SYS%'
AND username not in ('ANONYMOUS',
'DBSNMP',
'MGMT_VIEW',
'ORDPLUGINS',
'OUTLN',
'SI_INFORMATION_SCHEMA',
'WK_TEST',
'WKPROXY',
'XDB');
However, this will also filter legitimate non-system users whose names contain SYS
or end in SH
. User JOSH
will be lost.
Upvotes: 4