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
Related
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...?
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.
I have a problem when trying to create a cursor that uses tables filled after calling two other cursors, Oracle raised ORA-00942 exception - table or view does not exist. I tried to initialize the tables but it didnt change anything...
The idea was to recover buying prices(tsc.prxtar when tsc.achvte='A) and selling prices(tsc.prxtar when tsc.achvte='V') from a table, storing the results in two different tables and joining them at the end.
Does someone has any advice? Maybe an easier, more efficient way?
Thanks in advance!
DECLARE
CURSOR cursorA IS
SELECT pro.codpro as CodeProduit,
pro.nompro as NomProduit,
tsc.prxtar as PrixAchat
FROM pro
INNER JOIN tsc ON pro.codpro=tsc.codpro
WHERE tsc.achvte='A';
TYPE tableA IS TABLE OF cursorA%ROWTYPE;
tabA tableA:=tableA();
CURSOR cursorV IS
SELECT pro.codpro as CodeProduit,
pro.nompro as NomProduit,
tsc.prxtar as PrixVente
FROM pro
INNER JOIN tsc ON pro.codpro=tsc.codpro
WHERE tsc.achvte='V';
TYPE tableV IS TABLE OF cursorV%ROWTYPE;
tabV tableV:=tableV();
CURSOR cursorAV IS
SELECT tabA.CodeProduit,
tabA.NomProduit,
tabA.PrixAchat,
tabV.PrixVente
FROM tabA
INNER JOIN tabV ON tabA.CodeProduit=tabV.CodeProduit;
-- AND tabA.NomProduit=tabB.NomProduit;
TYPE tableAV IS TABLE OF cursorAV%ROWTYPE;
tableauDesPrix tableAV:=tableAV();
BEGIN
OPEN cursorA;
FETCH cursorA BULK COLLECT INTO tabA;
CLOSE cursorA;
OPEN cursorV;
FETCH cursorV BULK COLLECT INTO tabV;
CLOSE cursorV;
OPEN cursorAV;
FETCH cursorAV BULK COLLECT INTO tableauDesPrix;
CLOSE cursorAV;
END;
"Does someone has any advice? Maybe an easier, more efficient way?"
Why not write one SELECT statement which joins PRO to TSC twice?
SELECT pro.codpro as CodeProduit,
pro.nompro as NomProduit,
tsca.prxtar as PrixAchat,
tscv.prxtar as PrixVente
FROM pro
INNER JOIN tsc tsca ON pro.codpro = tsca.codpro
INNER JOIN tsc tscv ON pro.codpro = tscv.codpro
WHERE tsca.achvte = 'A'
AND tscv.achvte = 'V';
SQL is optimised for joins. It is more efficient to do everything in Plain Old SQL whenever possible. (There are edge cases where we might choose to do something in PL/SQL even though we could do it in SQL, but not here.)
You can not use the cursor name as a table name in the last cursor(cursorAV).
But I think you can achieve this using the single query as follows:
SELECT PRO.CODPRO AS CODEPRODUIT,
PRO.NOMPRO,
TSCA.PRXTAR AS PRIXACHAT,
TSCV.PRXTAR AS PRIXVENTE
FROM PRO
INNER JOIN TSCA
ON PRO.CODPRO = TSCA.CODPRO
INNER JOIN TSCV
ON PRO.CODPRO = TSCV.CODPRO
WHERE TSCA.ACHVTE = 'A'
AND TSCV.ACHVTE = 'V';
I have the sql id of a query. Now I want to get the machine name and IP of the machine from which this query was run.
I have already checked the sql id in V$SESSION and V$ACTIVE_SESSION_HISTORY but didn't get any results.
I am able to find the sql id in v$sql and LAST_LOAD_TIME is today(7 July 2016).
select LAST_LOAD_TIME from v$sql where SQL_ID='0jf4618m2u7aw' order by LAST_LOAD_TIME desc;
2016-07-04/17:26:02
2016-07-04/17:26:02
select * from V$SESSION where SQL_ID='0jf4618m2u7aw';
no rows selected
select * from V$ACTIVE_SESSION_HISTORY where SQL_ID='0jf4618m2u7aw';
no rows selected
Please help. Thanks in advance.
You have a couple of options...
If it is an active session/process, you can use v$session and v$process:
SELECT DISTINCT
MACHINE,
UTL_INADDR.GET_HOST_ADDRESS(MACHINE) AS IP_ADDR
FROM V$SESSION S,
V$PROCESS P
WHERE S.PADDR = P.ADDR
AND S.SQL_ID = '0jf4618m2u7aw';
If you want a historical view, the DBA_HIST_ACTIVE_SESS_HISTORY might be your friend:
SELECT DISTINCT
MACHINE,
UTL_INADDR.GET_HOST_ADDRESS(MACHINE) AS IP_ADDR
FROM DBA_HIST_ACTIVE_SESS_HISTORY DHASH
WHERE DHASH.SQL_ID = '0jf4618m2u7aw'
AND DHASH.SQL_EXEC_START > TRUNC(SYSDATE);
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'
;