查看Oracle中指定用户下包含的包、函数、存储过程及其对应内容语句——查看当前数据库的连接内容

一、需求分析

        在项目运维的时候,公司出于数据安全的考虑,对数据库的权限进行了控制,限制运维人员只能够通过堡垒机查看Oracle数据库内容,并且堡垒机只是设定了一个只读的账号查看数据库;这就导致了运维时在查看数据库的包、函数、存储过程内容有可能通过第三方数据库可视化工具查看不了,此时就需要使用sql语句进行查看了。

二、实现方法

2.1、查看到指定用户下对应的包、函数、存储过程内容

--【dba_source是数据字典表】获取到当前数据库实例的所有类型的源代码。它包括触发器、过程、函数、包和等等
select * from dba_source;

--查看到所有类型
select DISTINCT(type) from dba_source;

--查看所有包内容
select DISTINCT(name) from dba_source where owner='INTERFACEUSER' and type='PACKAGE';

--查看所有函数内容
select DISTINCT(NAME) from dba_source where owner='INTERFACEUSER' and type='FUNCTION';

--查看所有存储过程内容
select DISTINCT(NAME) from dba_source where owner='INTERFACEUSER' and type='PROCEDURE';

--查看指定包、函数、存储过程内容
select * from dba_source where name=upper('包、函数、存储过程的名称');

2.2、查看到当前的数据库连接内容

--查询数据库当前进程的连接数
select count(*) from v$process;

--查看数据库当前会话的连接数
select count(*) from v$session;

--查看数据库的并发连接数
select count(*) from v$session where status='ACTIVE'; 

--查看当前数据库建立的会话情况
select sid,serial#,username,program,machine,status from v$session; 

--查询数据库允许的最大连接数
select value from v$parameter where name = 'processes'; 

--修改数据库允许的最大连接数(注意:需要重启数据库才能实现连接数的修改)
alter system set processes = 300 scope = spfile;

--查看当前有哪些用户正在使用数据
select osuser,a.username,cpu_time/executions/1000000||'s',sql_fulltext,machine from v$session a,v$sqlarea b where a.sql_address = b.address order by cpu_time/executions desc;

注意:重启oracle数据库需要使用服务器本地的【sqlplus】命令工具执行如下命令才有用

shutdown immediate; 
startup; 

猜你喜欢

转载自blog.csdn.net/xiaochenXIHUA/article/details/130978387