I need the procedure for want custom packages from all users in database, I am giving step by step explanation and I need the query or some clues for how to display and select specific user.
1.List out the database users which already in database.
2.We have to select one specific user example Ranjith by input method.
3.After selecting the users should display the custom packages of selected users.
4.Next step is it should display the source code of all custom packages which you already selected users.
1.SELECT USERNAME FROM DBA_USERS (it will display all the users from database, After that I need to select specific users to display custom packages)
Thank you.
select object_name from dba_OBJECTs where owner = '{schema}' and object_type in ('FUNCTION','PACKAGE','PROCEDURE'); -- get user function,pkg, procedure.
select * from dba_source where owner = '{schema}' and name = '{object_name}' order by type,line asc; -- view source of objects.
If you want extract ddl of object, you use dbms_metadata.
select name,text from dba_source where owner = '{user}' and type in ('PACKAGE' ,'PACKAGE BODY','FUNCTION','PROCEDURE')
order by name,type,line asc; -- return all source code for specifed user
Related
I want to list all tables with current user using sql.
I know there are some way to get privileges, like EFFECTIVE_PRIVILEGES, but it only shows privileges which is granted by GRANT SELECT ~ on [TABLE] to [USERS].
You can query the schema information to get this - there's no SHOW TABLES or equivalent available.
Try:
SELECT TABLE_NAME FROM "SYS"."TABLES" WHERE SCHEMA_NAME='<database_name>'
which works for me.
You can also get Column Names in thsi way from the SYS.COLUMNS view
Basically I have a Database link (Oracle) called mylink.domain, in this link we can access foundation information like name of them members and other general information.
I would like to list all table's name in this link but i don't know how to do that.
Thanks in advance
You can access the all_tables view through the dblink:
select owner, table_name
from all_tables#dblink
order by owner, table_name;
Selecting the content of ALL_TABLES dictionary view will list you all tables your user has access to. Generally, it is not always possible to get a list of tables you dont have permissions for - they just do not show up. If your user has the SELECT ANY DICTIONARY priviledge, you can select the content of DBA_TABLES, which will always list all tables existing in the database.
select table_name from all_tables#dblinkname;
This shows all tables your linked user has access to.
Where I got the answer from
I am able to find all grants provided to a user but not for all users for a table . like TOAD shows under grants tab in the Table Describe window.
You need to check the below tables:
select * from USER_ROLE_PRIVS;
select * from USER_TAB_PRIVS;
select * from USER_SYS_PRIVS;
Also check this script which finds user who has previleges.
Description : Use this script to find which users have been granted
the privilege passed in. The script checks hierarchically for each
user granted the privileges via a role.
The output can be directed to either the screen via dbms_output or to a file via utl_file. The method is decided at run time by
choosing either 'S' for screen or 'F' for File. If File is chosen then
a filename and output directory are needed. The output directory
needs to be enabled via utl_file_dir prior to 9iR2 and a directory
object after.
I'm working with a legacy system that attempts to execute schema changes in SQL for specific users by first querying sysobjects as that user to determine if the object exists. If it does it creates an ALTER VIEW statement otherwise it creates a CREATE VIEW statement. In this case the view exists, but the query continues to fail to list the object.
For example:
setuser 'APPLICATION_DEV'
Select * from sysobjects o, sysusers u
where u.uid = o.uid
and u.name = N'APPLICATION_DEV'
The problem is that certain accounts in this database can run this query without error and it returns all of the objects owned by that user. Other accounts however get no records returned by this query. If I setuser to SA and run the query all of that users objects appear. The affected user is the owner of the schema and has create view permissions on the schema. I cannot find any differences in permissions between a working user and a non-working user account.
Is there a permission that I am missing that would restrict a user from querying their own objects in sysobjects?
Yes, I know sysobjects is obsolete, but I have no control over the actual code here and instead have to fix the database so their code will work as expected.
EDIT: Additional findings.
To complicate matters I can run this succesfully:
setuser 'APPLICATION_DEV'
Select * from sysusers
Where name = 'APPLICATION_DEV'
I can also execute this succesfully:
setuser 'APPLICATION_DEV'
Select * from sysobjects
Where uid = 308 --308 is the uid of the APPLICATION_DEV user
However, when I use a join either in the where clause or via INNER JOIN I then get no records. What would restrict my access to records purely based on the join? Index permissions?? I'm baffled.
For the particular user in user mapping check whether you have checked all the checkboxes apart from db_denydatareader and db_denydatawriter.
also check this
The SELECT permission was denied on the object 'sysobjects', database 'mssqlsystemresource', schema 'sys'
http://social.msdn.microsoft.com/Forums/en/sqlsecurity/thread/a2befd20-2a9b-4a60-95a9-3a80a1a99ea1
I have one database table which contains 8 columns. One of the columns is called IsAdmin (its data type is Bit). I have to show the user list in a grid view if and only if the signed-in user is an admin.
How can I do this? Which clause is used for this?
Not entirely sure that I understand you correctly. Is the "user list" that you're looking to display also the table that you're selecting from? My understanding is that this is what you need:
if exists (
select *
from MyUserList
where IsAdmin = 1
and UserName = SUSER_NAME()
)
begin
select *
from MyUserList /* Or whatever you need to do if the user is admin */
end
else
begin
/* Do whatever you need to do if the user is not an admin */
end
To me, doesn't sound like you need a clause but should be handled by business logic in your application.
e.g. if you only want to show the list if the signed-in user is an admin, then there's no point in running the query if the user is NOT an admin - it's a roundtrip to the db that is unneccessary.
Instead, in your application just have some logic that says "if signed-in user is an admin the populate the grid view, else don't"
I would probably recommend that this be done in the application instead of in SQL. Let the application do the checks on who is an admin and place that into a session or cookie and when the page loads do a check of the session/cookie to ensure the user is an admin and if they are show the information.
If you want it in SQL you should provide some additional information such as table structure and table names.
Matt
The solution is too simple,as you need to select specific data if the user is in role of admin and else another data may be selected or nothing, so do the following code :
select * from [UserList] where IsAdmin = #UserRole and UserID = #UserID
In this case you will select data relevant to this user ID and his role.
Hope that this is helpful according to my understanding of the problem.