how to find running procedure name - oracle

help to solve issue related session monitoring.
select sql_id,
(select o.owner || '.' || o.OBJECT_NAME
from dba_objects o
where o.OBJECT_ID = cu) object,
'LINE' ||'-' || program_line# line
from v$sql

Typically (if your user has relevant authority and you run a client like sqldeveloper, for example) you can do a session monitor by going to Tools > Session Monitor to view all open sessions.
Otherwise, you could use this very basic i have used many, many times to find open sessions in your DB running by the user you're logged into (if this is relevant);
select
oracle_username,
os_user_name,
locked_mode,
object_name,
object_type,
sysdate,
a.session_id,
a.process,
c.machine,
c.program,
c.module,
c.action,
c.logon_time,
c.last_call_et,
c.state
from
v$locked_object a,dba_objects b, v$session c
where
a.object_id = b.object_id
and C.sid = a.SESSION_ID
and ORACLE_USERNAME = user
order by OBJECT_NAME, ORACLE_USERNAME;
This SQL can be adjusted to your needs. Just remember that you can't view sessions if your user doesn't have the right permissions.
this is the best I could gather from your question, can you be more specific...?

Related

Fetch sql query with Machine Name

I want to fetch sql query with machine name where sql query has been run and machine name can belong's to any user. Please guide how is it possible to get that by joing tables like DBA_hist_sql or any other table.
I can suggest such variant
select
s.sql_id,
s.sql_text,
d.machine
from
v$sql s,
dba_hist_active_sess_history d
where
d.sql_id = s.sql_id
Maybe there is better variant or more related to your question. I hope it wil be helpful for you.
I let you links on documentation of these views.
DBA_HIST_ACTIVE_SESS_HISTORY
V$SQL
You can join DBA_HIST_ACTIVE_SESS_HISTORY and DBA_HIST_SQLTEXT , as long as the sql has been captured in the workload repository.
In the DBA_HIST_ACTIVE_SESS_HISTORY you have the field MACHINE, where you got the value of SYS_CONTEXT('userenv','host') .
You can join both views by sql_id.
However, the query will not be registered on the workload repository if it's not meaningful. You can modify this behaviour by changing settings of AWR using DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS
An example
select
distinct s.sql_id,
s.sql_text,
d.machine ,
u.username ,
d.program
from
gv$sql s inner join dba_hist_active_sess_history d
on ( d.sql_id = s.sql_id and S.INST_ID = D.INSTANCE_NUMBER )
inner join dba_users u on ( D.USER_ID = U.USER_ID )
where
u.username = '&1'
S.SQL_ID = '&2'
order by D.SAMPLE_TIME desc
You can apply the filter by username or sql_id, or both. keep in mind that the field USERNAME will show you the Oracle user who executed the query, not the operating system user behind that connection.

How to fix ORA-12801 error in SQL Developer when display tables in connection browser

Using SQL Developer 18.4 MacOSX, I'm getting this error
ORA-12801: error signaled in parallel query server P000
ORA-01722:
invalid number
When I try to display the tables list in the connections tab.
I've isolated the Query.
When I execute each part of the "union all" one by one, there is no error.
when I execute the all query you got the error.
When I disable the parallel option it works fine (ALTER SESSION disable PARALLEL query).
select * from (
SELECT o.OBJECT_NAME, o.OBJECT_ID ,'' short_name, NULL partitioned,
o.sharded,
case when o.sharded <> 'Y' then o.duplicated else 'N' end duplicated,
NULL iot_type,
o.OWNER OBJECT_OWNER, o.CREATED, o.LAST_DDL_TIME, O.GENERATED, O.TEMPORARY, NULL EXTERNAL
FROM SYS.Dba_OBJECTS O
WHERE O.OWNER = :SCHEMA
AND O.OBJECT_TYPE = 'TABLE'
union all
SELECT OBJECT_NAME, OBJECT_ID , syn.SYNONYM_NAME short_NAME, NULL partitioned,
o.sharded,
case when o.sharded <> 'Y' then o.duplicated else 'N' end duplicated,
NULL iot_type,
SYN.TABLE_OWNER OBJECT_OWNER, o.CREATED, o.LAST_DDL_TIME, O.GENERATED, O.TEMPORARY, NULL EXTERNAL
FROM SYS.Dba_OBJECTS O, sys.user_synonyms syn
WHERE syn.table_owner = o.owner
and syn.TABLE_NAME = o.object_NAME
and o.object_type = 'TABLE'
and :INCLUDE_SYNS = 1
)

getting the currently logged on user and the number of valid stored procedure in sql

I would like to find out if its possible to get the number of valid and invalid stored procedures in SQL. Also the currently logged on user and the current time
To get the invalid objects use
SELECT *
FROM dba_objects
WHERE object_type IN ('PACKAGE'
, 'PACKAGE BODY'
, 'PROCEDURE'
, 'FUNCTION')
AND status <> 'VALID';
OR
SELECT STATUS, COUNT(*)
FROM dba_objects
WHERE object_type IN ('PACKAGE'
, 'PACKAGE BODY'
, 'PROCEDURE'
, 'FUNCTION')
GROUP BY status
for just a count of the statuses.
You might need to tweak the list of object types depending on what you want and you may want to limit it by OWNER as well.
The following shows the current time and a few methods of getting the user (schema, OS and the user from 'client identifier').
I suggest you try it and see which one you actually want and/or have populated.
SELECT TO_CHAR(SYSDATE, 'HH24:MI:SS') AS current_NLS
, TO_CHAR(SYS_EXTRACT_UTC(SYSTIMESTAMP),'HH24:MI:SS') AS UTC_TIME
, USER
, SYS_CONTEXT('USERENV', 'OS_USER')
, REGEXP_SUBSTR(SYS_CONTEXT('userenv', 'client_identifier'), '^[^:]*')
FROM DUAL;

How do I get Oracle, see what procedures are running?

Good afternoon. How do I get Oracle, see what procedures are running?
Depending on your needs, this might suffice (but relies on access to v$session and dba_objects):
select 'CALLED PLSQL', vs.username, d_o.object_name -- whatever info you need
from dba_objects d_o
inner join
v$session vs
on d_o.object_id = vs.plsql_entry_object_id
union all
select 'CURRENT PLSQL', vs.username, d_o.object_name
from dba_objects d_o
inner join
v$session vs
on d_o.object_id = vs.plsql_object_id
As per the docs:
PLSQL_ENTRY_OBJECT_ID - ID of the top-most PL/SQL subprogram on the stack; NULL if there is no PL/SQL subprogram on the stack
PLSQL_OBJECT_ID - Object ID of the currently executing PL/SQL subprogram; NULL if executing SQL
select 'CALLED PLSQL', vs.username, d_o.object_name -- whatever info you need
from dba_objects d_o
inner join
v$session vs
on d_o.object_id = vs.plsql_entry_object_id
union all
select 'CURRENT PLSQL', vs.username, d_o.object_name
from dba_objects d_o
inner join
v$session vs
on d_o.object_id = vs.plsql_object_id

How to identify what locked PL/SQL package (Oracle 10.0.4.2)?

I was trying to recompile PL/SQL package and no avail. because something obtained the lock and that wasn't released for long time. As soon as I kill all sessions I was able to recompile but encounter the same behavior (i.e. locked package) and I wonder what tools are avail to identify what could of obtain it and never release it? This happen on (Oracle 10.2.0.4). Greatly appreciate for your help.
I think you mean 10.2.0.4, as there isn't a 10.0.x.x version series.
select * from v$locked_object lo join dba_objects o on lo.object_id = o.object_id
where o.object_name = 'xxPACKAGE NAMExx' and o.object_type = 'PACKAGE';
select l.session_id, l.owner, l.name, l.type, inst_id, sql_id
, a.sql_fulltext
, 'alter system disconnect session '''||s.sid||','||s.serial#||',#'||inst_id||''' immediate' ddl
from dba_ddl_locks l
join gv$session s on s.sid = l.session_id
join gv$sqlarea a using(inst_id, sql_id)
where l.name = 'OBJECT_NAME'
;

Resources