oracle database AUDIT doesn't show SQL text and bind values - oracle

Based on this tutorial I have configured auditing on a database with these options:
AUDIT ALL BY db BY ACCESS;
AUDIT SELECT TABLE, UPDATE TABLE, INSERT TABLE, DELETE TABLE BY db BY ACCESS;
AUDIT EXECUTE PROCEDURE BY db BY ACCESS;
I prepare query from java and run a SELECT query. DBA_AUDIT_TRAIL table shows my SELECT query but SQL_TEXT and SQL_BIND fields are empty. How can I see them? Should I enable any other option? I'm using Oracle 11.2 Express Edition. Is this because It is express edition?

The column SQLTEXT and SQLBIND are populated only when AUDIT_TRAIL option is set to db, extended. Here is an example:
SQL> alter system set audit_trail=db,extended scope=spfile;
System altered
Restart the instance.
SQL> audit select on your_table;
Audit succeeded
SQL> select sqltext from sys.aud$ where obj$name = 'YOUR_TABLE';
SQLTEXT
--------------------------------------------------------------------------------
null
SQL> select count(*) from your_table;
COUNT(*)
----------
3
SQL> select sqltext from sys.aud$ where obj$name = 'YOUR_TABLE';
SQLTEXT
--------------------------------------------------------------------------------
select count(*) from your_table
SQL>

Related

How to get the table name in trigger on which ddl operation will be performed

I want to do something like
create or replace trigger t1 before ddl on database
begin
insert into table1 values(//the table name on which the ddl will be performed);
end;
so if i create a table named "Hello" than "Hello"(table name) will be inserted in table1
so i don't know how to fetch the table name actually
That's show here in the Database Docs
So you could do something like...
CREATE OR REPLACE TRIGGER ddl_trig
AFTER DDL
ON DATABASE
BEGIN
INSERT INTO loguser.ddl_log
(user_name, ddl_date, ddl_type,
object_type, owner,
object_name)
VALUES
(ora_login_user, SYSDATE, ora_sysevent,
ora_dict_obj_type, ora_dict_obj_owner,
ora_dict_obj_name);
END ddl_trig;
/
BUT, you shouldn't build your own auditing software/code. You should instead use the database's built in auditing system.
See this.
Disclaimer: I work for Oracle and am a product manager on the database team.

ORA-14450 GTT alter table issue

Iam facing a issue while altering the GTT table.
I need to find the active users on that table, Can someone help in query regarding how to find the active users on the specific object in oracle database
As far as I can tell, you didn't explain what problem you're trying to solve, but rather what you think that might help you solve it. So, let me try to guess.
Here's a global temporary table (GTT):
SQL> create global temporary table gtt (id number) on commit preserve rows;
Table created.
SQL> insert into gtt values (1);
1 row created.
SQL> commit;
Commit complete.
You're trying to alter it, but - it fails:
SQL> alter table gtt add name varchar2(10);
alter table gtt add name varchar2(10)
*
ERROR at line 1:
ORA-14450: attempt to access a transactional temp table already in use
OK, so - delete row(s) and commit, then try again:
SQL> delete from gtt;
1 row deleted.
SQL> commit;
Commit complete.
SQL> alter table gtt add name varchar2(10);
alter table gtt add name varchar2(10)
*
ERROR at line 1:
ORA-14450: attempt to access a transactional temp table already in use
Still no luck. But, if you truncate the table, then it works:
SQL> truncate table gtt;
Table truncated.
SQL> alter table gtt add name varchar2(10);
Table altered.
SQL>
If that's not what you're after, then see if this answers your question: connect as a privileged user (such as SYS, if you don't have any other) and run such a query: it shows who owns the GTT, its name, who locked it (which Oracle user) and which operating system user is it (that might help you to contact those people):
SQL> select b.owner,
2 b.object_name,
3 a.oracle_username,
4 a.os_user_name
5 from v$locked_object a, dba_objects b
6 where a.object_id = b.object_id;
OWNER OBJECT_NAM ORACLE_USERNAME OS_USER_NAME
--------------- ---------- --------------- ------------------------------
SCOTT GTT SCOTT littlefoot
SQL>

LAST_DDL_TIME for GLOBAL TEMPORARY TABLE -- Oracle 11g bug?

When I create a GLOBAL TEMPORARY TABLE in Oracle 11g (11.2.0.1.0), and then add a new column to it, Oracle does not update the LAST_DDL_TIME column of the system catalog views (e.g. DBA_OBJECTS):
create global temporary table test# (foo varchar2(3));
select last_ddl_time from dba_objects where object_name='TEST#';
-- Shows created time
-- Wait a minute
alter table test# add (bar varchar(3));
select last_ddl_time from dba_objects where object_name='TEST#';
-- Shows NO UPDATE
-- Wait a minute
alter table test# drop (bar);
select last_ddl_time from dba_objects where object_name='TEST#';
-- Shows time when column was dropped
However, when I execute the same sequence of SQL statements in Oracle 12c (12.1.0.2.0), then LAST_DDL_TIME does reflect newly-added columns.
create global temporary table test# (foo varchar2(3));
select last_ddl_time from dba_objects where object_name='TEST#';
-- Shows created time
-- Wait a minute
alter table test# add (bar varchar(3));
select last_ddl_time from dba_objects where object_name='TEST#';
-- Shows time when column was added
-- Wait a minute
alter table test# drop (bar);
select last_ddl_time from dba_objects where object_name='TEST#';
-- Shows time when column was dropped
This behavior appears to be very specific to adding columns to GLOBAL TEMPORARY TABLES, and to Oracle 11g; renaming or dropping columns does affect LAST_DDL_TIME as expected.
Is this a known Oracle 11g bug?! If so, is there an official Oracle patch update for it?

oracle database to find recently added column in table or database(oracle)

I want to find the recently added column to existing table.
How to find recently added column in table or database(oracle).
Recently the table and the databases of our web application got modified and some of the table got altered.
Ideally you should have restricted access to your Production database, together with a build process which applies scripts out of source control, rather than allowing people to change things using TOAD. It's pretty hard to conduct forensics in a free-fire zone.
You can find out which tables have changed by interrogating the data dictionary:
SQL> select object_name from user_objects t
2 where t.object_type = 'TABLE'
3 and t.last_ddl_time > trunc(sysdate)
4 /
no rows selected
SQL> alter table t23 add col_3 number
2 /
Table altered.
SQL> select object_name from user_objects t
2 where t.object_type = 'TABLE'
3 and t.last_ddl_time > trunc(sysdate)
4 /
OBJECT_NAME
----------------------------------------------------------
T23
SQL>
This won't tell you what the change was, or who did it. To get better information you need a proper audit trail. At the very least you should enable auditing of DDL statements....
SQL> audit ALTER TABLE;
Audit succeeded.
SQL>
Find out more.

Select from one DB and insert in another DB

I need a sql query in which
Select from DB1 and insert into DB2 in one single query
Example:
DB1
Select username,account_status from dba_users;
DB2
Insert into table User_id
You have to create a database link (this should probably be done by a DBA). Once that is in place, you can select from the other database and write a statement like this:
INSERT INTO MyTable
SELECT * from MyTable#DB2
[Edit]
You can't without a database link.

Resources