Track DDL statements for schema.
Dear all,
I want to track all DDL statements being performed on particular schema.
I want to capture entire sql statement being run.
How can I achive this.
Please advice.
Waiting for your reply.
Regards,
Hi all,
I have used this trigger to track ddl.
create table perfstat.stats$ddl_log(
user_name varchar2(30),
ddl_date date,
ddl_type varchar2(30),
object_type varchar2(18),
owner varchar2(30),
object_name varchar2(128)
create or replace triggerDDLTrigger
AFTER DDL ON DATABASE
BEGIN
insert into
perfstat.stats$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;
It's working fine ,
But I want to capture entire sql statement into stats$ddl_log table.
What to modify in table or trigger that I could achive this.
Waiting for your reply.
Thanks and regards...
Similar Messages
-
How to Generate DDL Statement for PSAPROLL Tablespace on Oracle9i-HP_UX
Hi,
I am having SAP R3 46C installed with Oracle 9i on HP_UX 11i system.
I want to generate required DDL statements for PSAPROLL Tablespace/Rollback Segments as Backup/recovery purpose, before converting it into PSAPUNDO.
Its easy to find & store required DDL statements using OEM. But, I am not able to locate oemapp (under $ORACLE_HOME/bin directory) application in the installation.
The current patch level of installed oracle is
I want to start OEM in HP_UX system, if it is possible.
otherwise,
I want to know the other alternatives to generate the required DDL statements.
Thanks in advance.
Regards,
Bhavik G. ShroffHi Stefan,
On windows Platform it is very easy to get DDL info for any object of database.
But, I was not able to start OEM in HP_UX system.
I have done my job complete using this good package of Oracle9i, in this way.
SQL> SET heading off
SQL> SET long 10000
SQL> SET pages 100
SQL> SELECT dbms_metadata.get_ddl(u2019TABLESPACEu2019,'PSAPROLLu2019)
FROM DBA_TABLESPACES;
O/P:
CREATE TABLESPACE "PSAPROLL" DATAFILE
'/oracle/RQ1/sapdata1/roll_1/roll.data1' SIZE 681574400 REUSE ,
'/oracle/RQ1/sapdata1/roll_2/roll.data2' SIZE 3145719808 REUSE
LOGGING ONLINE PERMANENT BLOCKSIZE 8192
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1048576 SEGMENT SPACE MANAGEMENT MANUAL
SQL> SELECT dbms_metadata.get_ddl(u2019ROLLBACK_SEGMENTu2019,'PRS_0u2019)
FROM DBA_SEGMENTS;
CREATE ROLLBACK SEGMENT "PRS_0" TABLESPACE "PSAPROLL"
STORAGE(INITIAL 10485760 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 32765
Also follow this useful links:
[DDL Generation--Oracle's Answer to Save You Time and Money|http://www.dbasupport.com/oracle/ora9i/DDLgen2.shtml]
[DDL Generation--Oracle's Answer to Save You Time and Money|http://www.dbasupport.com/oracle/ora9i/DDLgen3.shtml]
Good.
Thanks a lot. -
Hi all
I want to track all DDL statements fiered on the database like Drop, Alter, Truncate, Create.
I tried looking in metalink and found out that I have to right a trigger for it.
but couldn't find any script for it.
Can anyone help me with this.Writing triggers would be one way. The other ways is to enabling DDL auditing. Refer oracle docs. also search in this forum or http://www.asktom.oracle.com site.
Jaffar -
Failed to track ddl statements
Hi
We are using oracle 9.2.0 database and set up logminer in order to track ddl and dml changes but
returning previous data i mean latest archived archive logfile " ARC00140.001" but it showing the previous archive log file when
query the below dictionay view
SQL> select name from v$archived_log where dictionary_begin='YES';
NAME
D:\ORACLE\ORA92\RDBMS\ARCH\ARC00007.001
SQL> select name from v$archived_log where dictionary_end='YES'
2 ;
NAME
D:\ORACLE\ORA92\RDBMS\ARCH\ARC00007.001
And done some modifications in scott schema and issued
alter system switch log file 15 or 20 times and follwed the follwing steps to setup logminer
set utl_file_dir='d:\oracle' in spfile using scope option
SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA
sql> exec dbms_logmnr_d.build('dict.ora','d:\oracle')
SQL> exec dbms_logmnr.add_logfile(logfilename=>'D:\ORACLE\ORA92\RDBMS\ARCH\AR
117.001', options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
SQL> exec dbms_logmnr.add_logfile(logfilename=>'D:\ORACLE\ORA92\RDBMS\ARCH\AR
118.001', options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
SQL> exec dbms_logmnr.add_logfile(logfilename=>'D:\ORACLE\ORA92\RDBMS\ARCH\AR
119.001', options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
SQL> exec dbms_logmnr.add_logfile(logfilename=>'D:\ORACLE\ORA92\RDBMS\ARCH\AR
120.001', options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
SQL> exec dbms_logmnr.add_logfile(logfilename=>'D:\ORACLE\ORA92\RDBMS\ARCH\AR
121.001', options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
SQL> exec dbms_logmnr.add_logfile(logfilename=>'D:\ORACLE\ORA92\RDBMS\ARCH\AR
122.001', options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
SQL> exec dbms_logmnr.add_logfile(logfilename=>'D:\ORACLE\ORA92\RDBMS\ARCH\AR
123.001', options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
SQL> exec dbms_logmnr.start_logmnr(dictfilename=>'d:\oracle\z.ora',options => -
DBMS_LOGMNR.DDL_DICT_TRACKING);
PL/SQL procedure successfully completed.
SQL> select count(*) from v$logmnr_contents;
COUNT(*)
0
Thnaks inadvance
MohanHi
We are using oracle 9.2.0 database and set up logminer in order to track ddl and dml changes but
returning previous data i mean latest archived archive logfile " ARC00140.001" but it showing the previous archive log file when
query the below dictionay view
SQL> select name from v$archived_log where dictionary_begin='YES';
NAME
D:\ORACLE\ORA92\RDBMS\ARCH\ARC00007.001
SQL> select name from v$archived_log where dictionary_end='YES'
2 ;
NAME
D:\ORACLE\ORA92\RDBMS\ARCH\ARC00007.001
And done some modifications in scott schema and issued
alter system switch log file 15 or 20 times and follwed the follwing steps to setup logminer
set utl_file_dir='d:\oracle' in spfile using scope option
SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA
sql> exec dbms_logmnr_d.build('dict.ora','d:\oracle')
SQL> exec dbms_logmnr.add_logfile(logfilename=>'D:\ORACLE\ORA92\RDBMS\ARCH\AR
117.001', options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
SQL> exec dbms_logmnr.add_logfile(logfilename=>'D:\ORACLE\ORA92\RDBMS\ARCH\AR
118.001', options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
SQL> exec dbms_logmnr.add_logfile(logfilename=>'D:\ORACLE\ORA92\RDBMS\ARCH\AR
119.001', options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
SQL> exec dbms_logmnr.add_logfile(logfilename=>'D:\ORACLE\ORA92\RDBMS\ARCH\AR
120.001', options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
SQL> exec dbms_logmnr.add_logfile(logfilename=>'D:\ORACLE\ORA92\RDBMS\ARCH\AR
121.001', options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
SQL> exec dbms_logmnr.add_logfile(logfilename=>'D:\ORACLE\ORA92\RDBMS\ARCH\AR
122.001', options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
SQL> exec dbms_logmnr.add_logfile(logfilename=>'D:\ORACLE\ORA92\RDBMS\ARCH\AR
123.001', options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
SQL> exec dbms_logmnr.start_logmnr(dictfilename=>'d:\oracle\z.ora',options => -
DBMS_LOGMNR.DDL_DICT_TRACKING);
PL/SQL procedure successfully completed.
SQL> select count(*) from v$logmnr_contents;
COUNT(*)
0
Thnaks inadvance
Mohan -
Generate "Drop-Statements" for DB-Objects
Hi,
is it possible to generate drop statements for the different DB-Objects?
Most of the time when I generate DDL - Statements for Tables and Sequences I need a drop statement for this object to recreate.
And is it possible to supress the schema-name?
CREATE TABLE "SCHEMA"."TABLE"
Regards, Juergen
Message was edited by:
Juergen.Schuster
Message was edited by:
Juergen.SchusterI apologize. I had interpreted the first posting in the thread differently than you. I had read "Most of the time when I generate DDL - Statements for Tables and Sequences I need a drop statement for this object to recreate" to mean that when the user generates the DDL for a table or sequence include a DROP statement prior to the CREATE statement. If these were automatically generated and the user accidentally ran the script, they may lose data in the table or the value of the sequence. That is why I was suggesting that the DROP statement generation be configurable when DDL for a table is generated.
My mistake,
Mike -
Using variable in from close of select statement for LOV
Hi all,
I had a select list based on a query with a variable in it for the database schema. Something like this:
"select name, id from &SCHEMA..countries order by name". This warked in version 1.4.4..., I don't remember the rest. Now we upgraded to version 1.6.0.00.87 and I am trying to change the condition for this select item but I recieve this error:
1 error has occurred
LOV query is invalid, a display and a return value are needed, the column names need to be different. If your query contains an in-line query, the first FROM clause in the SQL statement must not belong to the in-line query.
Whatever I'm trying to change for this item, it always gives me this error when I click on "Apply Changes" button. Everything works fine when I remove &SCHEMA. from the query and instead write directly the database schema name.
Can you help me?Sabiha,
This is a case where the builder cannot parse the query at design time because there is no state for &SCHEMA. in the session. You can try this trick, change the lov query to: if htmldb_application.get_current_flow_sgid(:APP_ID) = htmldb_application.get_sgid then
return 'select name d, id r from &SCHEMA..countries order by name';
end if;Notice also the addition of aliases for the column names.
Scott -
How to execute sets of DDL Statements in 1 command?
Hi All,
I've been trying to look for a way to run a set of DDL statements. I normally have text files with DDL Statements on it. So what I do is load the contents of this text file into a Textbox and then set the Textbox.Text as the CommandText of my command object. Unfortunately I get errors.
Here's my code...
Private Sub btnLoadFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim OpenDiag As New OpenFileDialog
Dim txtReader As StreamReader
OpenDiag.ShowDialog()
If OpenDiag.FileName <> "" Then
txtReader = File.OpenText(OpenDiag.FileName)
CommandTextBox.Text = txtReader.ReadToEnd
End If
End Sub
Private Sub btnExecute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim myConn As New OracleConnection(My.Settings.ConnectionString)
Dim myComm As New OracleCommand(CommandTextBox.Text, myConn)
Try
myConn.Open()
myComm.ExecuteNonQuery()
myConn.Close()
Catch ex As OracleException
MessageBox.Show(ex.Code & ": " & ex.Message)
End Try
End SubThe errors that I get are
"ORA-00900: Invalid SQL Statement"
- Not sure how I get this but I noticed that if i had remarks/comments in my text file, this is the error that i get. Although i don't get this error if i execute in SQL Plus.
"ORA-00911: Invalid Character"
- after removing the remarks/comments, i get this error. i tried removing the semi-colon ";" then it works okay if i'm running 1 DDL statement in my file.. but if i my file contains to DDL statements for example, then i get the this error "ORA-00922: Missing or Invalid Options".
can anyone help me with this?
thanks.yes. i have BEGIN and END in their corresponding places.
i found out that removing linefeeds and semi-colons somehow fixes the problem for DDL statements. also, if i use a RichTextBox and uses its RichTextBox.LoadFile(filename, RichTextBoxStreamType.PlainText) instead of the File.OpenText(filename), it works fine as well. although its not something i would want. so what i did was to create a PL/SQL Anonymous Block instead. this too works if i use a RichTextBox.LoadFile instead of a textbox. but i'm using these controls to see the contents. eventually i will need to use a variable to store the contents of the file and i'm worried that it won't work with it.
unfortunately it doesn't work when i use a string. i'm guessing because of the linefeeds and semi-colons are still there. -
Is there any function that returns the latest DDL statement
can anyone tell me if there is any FUNCTION that returns latest DDL statement performed in a schema.
OR
if there is any TABLE that will be populated with latest
DDL statement in schema.
THANK YOU.The table all_objects (and/or dba_objects) contains a column called last_ddl_time. Thus, a query like
scott@jcave > SELECT max(last_ddl_time)
2 FROM all_objects
3 WHERE owner = 'SCOTT';
MAX(LAST_DDL_TI
28-NOV-03will tell you the last time any object owned by SCOTT had DDL issued against it.
Justin
Distributed Database Consulting, Inc.
www.ddbcinc.com/askDDBC -
Hi
After I issue, DDL statements for example:
create table statement.
The blocks must be allocated to this empty table.
These blocks are allocated in buffercache first.
and then after a checkpoint these blocks are written to disk.
Is it correct?Pavan,
I amnot sure that I am getting you. Look here,
SQL*Plus: Release 11.1.0.6.0 - Production on Thu Feb 19 16:30:22 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> create table hwm ( a number); <-- I made a table here.
Table created.
--Looking at the info of it in the dictionary.
SQL> select blocks, empty_blocks
2 from user_Tables where table_name='HWM';
BLOCKS EMPTY_BLOCKS
SQL> exec dbms_Stats.gather_Table_Stats(user,'HWM');
PL/SQL procedure successfully completed.
SQL> select blocks, empty_blocks
2 from user_Tables where table_name='HWM';
BLOCKS EMPTY_BLOCKS
0 0
--I am adding a row into the table and checking the info again.
SQL> insert into hwm values(10);
1 row created.
SQL> commit;
Commit complete.
SQL>
SQL> exec dbms_Stats.gather_Table_Stats(user,'HWM');
PL/SQL procedure successfully completed.
SQL> select blocks, empty_blocks
2 from user_Tables where table_name='HWM';
BLOCKS EMPTY_BLOCKS
5 0 <<---- 5 blocks are being maintained now.
SQL>Oracle does maintain the HWM count with the help of an internal parameter ,*bumphighwater_mark_count * but I am seeing this parameter value as 0 only since 9i. Here it is on my 11g box.
SQL> conn / as sysdba
Connected.
SQL> select KSPFTCTXDVL,kspftctxdf,ksppinm
2 from x$ksppcv2 a,x$ksppi b
3 where a.indx=b.indx and b.ksppinm like '%bump%'
4 /
KSPFTCTXDVL
KSPFTC
KSPPINM
0
TRUE
_bump_highwater_mark_count
SQL>I have also seen some times 8 blocks being picked up by Oracle. So may be now the count is maintained by oracle completely. Now you tell me what does PCTUSED has to do with it? I am not able to understand the relation that you have presented for avg_row_length and HWM. If possible, post a reference too where its mentioned.
Here is a small demo which does show that HWM got increased next time by 8 times,
SQL> begin
2 for i in 1..1000 loop
3 insert into hwm values(i);
4 end loop;
5 end;
6 /
PL/SQL procedure successfully completed.
SQL> /
PL/SQL procedure successfully completed.
SQL> /
PL/SQL procedure successfully completed.
SQL> exec dbms_Stats.gather_Table_Stats(user,'HWM');
PL/SQL procedure successfully completed.
SQL> select blocks, empty_blocks
2 from user_Tables where table_name='HWM';
BLOCKS EMPTY_BLOCKS
13 0
SQL>Aman.... -
Hi
During DDL statements for example: create table statement.
Is the segment created inside the buffercache first and after a checkpoint it is written to disk?
Is this the correct order for DDL statements except Direct Path Load?Pavan Kumar wrote:
Hi Aman,
I mean to say if any thing needs to effect (as per the Buffer Cache) with respect to the ASSM, it would be starts from tablespace point of view level (Logical level), so and then it will be effected or goes further to SGA (Instance level). Reverse of Tree as per my knowledge.
- Pavan Kumar NI am still not clear. What do you mean by saying that the tablespace level and SGA level? When there is a block accessed, correspondingly , oracle accesses a buffer from the cache, formats it, pushes it. See my blog post which does show that. What does it mean by tablespace level over here? If you mean that this tablespace block is accessed first than its not right to say so. I ,actually, didn't understand the context of the line, sorry!
Aman.... -
SQL-error "-955-Duplicate name" in DDL statement
Hi!
During upgrade preparations (PREPARE) i got follwing problem activating a table TAREF in SOLMAN32/MaxDB 7.5
estos100:smpadm 79> more MVNTTOOL.ELG
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MVNTABS errors and RETURN CODE in P060227.SMP
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2EETP345 22:16:03: Retcode 1024: SQL-error "-955-Duplicate name" in DDL statement for "TAREF
2EETP345 "
2EETP334 22:16:03: error in DDL, nametab for "TAREF" not activated
1 ETP111 exit code : "8"
estos100:smpadm 80>
When looking from the ABAP perspective (se14 -> table "TAREF" -> Indexes) I see that the table has two indexes:
"0 X Primary index"
"1 X Index on Object Type".
When looking at details for "index 1" it says "does not exist in database".
How do I solve this ABAP dictionary inconsistancy?
Regards,
Fredrik
Message was edited by: Fredrik RosengrenHi Fredrik,
please open an OSS message for your issue.
Kind regards,
Roland -
How to gather table stats for tables in a different schema
Hi All,
I have a table present in one schema and I want to gather stats for the table in a different schema.
I gave GRANT ALL ON SCHEMA1.T1 TO SCHEMA2;
And when I tried to execute the command to gather stats using
DBMS_STATS.GATHER_TABLE_STATS (OWNNAME=>'SCHMEA1',TABNAME=>'T1');
The function is failing.
Is there any way we can gather table stats for tables in one schema in an another schema.
Thanks,
MK.You need to grant analyze any to schema2.
SY. -
How to trace every dml statement for a schema/ database
hi,
how to trace every dml statement for a schema/ database
PFile Entrie
init.ora Parameter Example event='1401 trace name errorstack, level 12';
tkprof orcl_ora_3632.trc b.txt
after these two steps I am not able to see the sql statements in trace ...
Please suggest.
Thanks & Regards,Hi,
Trace Event 1401 will create a trace file and dumps the information when ORA-01401 error occurs. This error occurs when "inserted value too large for column"
You will see the trace file getting populated only when you encounter ORA-01401 error.
Regards -
How to know which user has executed which ddl statement
Hi All,
Last week i faced some problem, like some one has truncated the table , so luckily i have the schema backup so i restored it till the last backup taken.
but i want to know who has executed this ddl statement.
i know there are some utilities are avaible with oracle, so please describe me the easiest and quickest way to get this.
Regards
AsifIn order of descending simplicity
- Use the principle of least privilege to restrict the privileges users have in the database to ensure that they cannot do things like truncating a table
- Enable auditing of potentially problematic statements. This has to be done before the damage is done, though
- Create a DDL trigger that logs when users issue DDL. This also must be done before the damage is done.
- Use LogMiner to go through the archived log files that were generated at the time the table was truncated. This assumes that the database is in ARCHIVELOG mode and that you have the archived logs from last week. Using LogMiner to track down the culprit is also likely to be relatively time-intensive
Justin -
DDL statements and dynamic sql in stored procedure
I created a stored procedure to create and drop tables, using dynamic sql.
When I try to do the inserts using dynamic sql, i.e
v_string := 'INSERT statement';
EXECUTE IMMEDIATE v_string;
I get the following error message:
ERROR at line 1:
ORA-00942: table or view does not exist
ORA-06512: at line 63
Line 63 happens to be the line that the EXECUTE IMMEDIATE v_string; statement is in.
I am able to describe the table that the inserts are being made into, so I know that the table exists.
Any idea why I'm getting this error message would be appreciated.Yes I do and I have been able to create other tables using dynamic sql.
The table that I am having problems with SELECTs data from another table to get its column values; within the SELECT statement, the CAST function is used:
ie. CAST(CASE SUBSTR(CAST(E_MOD AS VARCHAR(7)),2,3)
WHEN 'AAA' THEN 'A55'
ELSE ............
I get the following error message:
ERROR at line 18: (this line starts the CAST statement)
ORA-06550: line 18, column 13:
PLS-00103: Encountered the symbol "AAA" when expecting one of the following:
. ( * @ % & = - + ; < / > at in is mod not rem return
returning <an exponent (**)> <> or != or ~= >= <= <> and or
like between into using || bulk
When I remove the quotes or add another single quote, the same error cascades to 'A55'.
After doing the same for the next error, I get the error message below:
ERROR at line 1: (this line has the EXECUTE IMMEDIATE statement)
ORA-00936: missing expression
ORA-06512: at line 6
Any idea what the problem could be?
Also is there another way to have DDL statements as stored procedures other than using dynamic sql or the DBMS_SQL package?
Maybe you are looking for
-
Hellow, so i have Adobe Illsutrator cs6 version 16.0.0. I was so excited to update this version to a retina display compatible one (16.0.3). I downloaded he extension 24.2 Mb from the official adobe website, and when i tried to install the update, by
-
Adding text boxes, etc on top of background image (bitmap)
I have an image (saved as a bitmap that I created in a drawing program) and I want to add it as a background to one of my panels in my swing application. I need to be able to put stuff on top of it, such as text boxes, etc. What is the best way to ge
-
my question is: How to transform a list of characters of values of time that have format HH:MMS to a list or adjustment of numerical values, to be able to use them in a code of LabVIEW? The numeric data are going to be used to plot them in a graph XY
-
log shipping backup jobs is failing due to the below error. The job failed.the job was invoked by schedule(ls backup_server name).The last step to run was step 1.(log shipping backup job step) executed as user:username.the step failed. could any one
-
Share macbook internet with xbox 360
hi i got a xbox 360 recently and i do not want to buy the expensive network adapter. i use to use a toshiba laptop to connect the xbox to internet but now i have a macbook and i need to know how to configure it. if you know how to configure your xbox