Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Is there a way to capture complete query along with the bind values in oracle ?

Sai ChallaSep 9 2015 — edited Sep 10 2015

I am trying to capture all the queries being executed on a table in the database. These queries will be stored in a table and will be later executed on a different database to keep both the databases synchronized. In the trigger we are using the below select statement to capture the query :

select sq.sql_text from v$open_cursor oc,v$sql sq where sid = sys_context('USERENV','SID') order
by sq.last_active_time desc ;

But, if the queries are being executed as prepared statements then the above query being used is capturing the sql statements as:

UPDATE <TABLE_NAME> SET COL1_NAME = :1   WHERE COL2_NAME =:2   AND COL3_NAME = :3

I am unable to get the values of the above fields in my query. Is there any other way that I can achieve this and get the complete query ?

Comments

Martin Preiss

you can create a sql trace with event 10046 and a sufficient level: Event 10046 – Full List of Levels | Striving for Optimal Performance. But I would not use this to synchronize databases.

unknown-951199

8ae0046f-173b-4759-a637-cef1da3bc23b wrote:

I am trying to capture all the queries being executed on a table in the database. These queries will be stored in a table and will be later executed on a different database to keep both the databases synchronized. In the trigger we are using the below select statement to capture the query :

select sq.sql_text from v$open_cursor oc,v$sql sq where sid = sys_context('USERENV','SID') order
by sq.last_active_time desc ;

But, if the queries are being executed as prepared statements then the above query being used is capturing the sql statements as:

UPDATE <TABLE_NAME> SET COL1_NAME = :1   WHERE COL2_NAME =:2   AND COL3_NAME = :3

I am unable to get the values of the above fields in my query. Is there any other way that I can achieve this and get the complete query ?

There are easier ways to keep table data in synch.

In fact, I doubt that anyone could devise a more convoluted method than what you are proposing.

When doing DML against this table, does the result set ever depend upon data contained in any other table?

If so, exactly how to you ensure that data matches what is/was in the SOURCE database at the time the DML executed?

I choose not to provide you a bigger shovel to allow you to produce a larger hole faster.

Sai Challa

Can you suggest how can we do this through other methods ?

Sai Challa

Yes, there are scenarios in which the data in one table may be depending on the others. But, the trigger will be created on all the tables in the schema such that any modifications will be captured and then executed to achieve synchronization. Can you suggest any other methods through which I can achieve this requirement?

vijayrsehgal-Oracle

do you want to do it without using products available to do this?  goldengate is one such product which can help you achieve databases in sync.

Martin Preiss

depends on what you actually try to achieve. Materialized Views using a db link to access the data from the source node could be an option.

Sai Challa

Thats right, we need to do it manually without using any products .

Sai Challa

Can you elaborate more on this please?

sgalaxy

Hi,

Defining auditing in xml extended format :

http://docs.oracle.com/cd/E11882_01/server.112/e40402/initparams017.htm

Is this acceptable?

Did you try it?

Greetings,

Sim

Sai Challa

Please correct me if I am wrong here, I think auditing is going to capture all the records being run in the database. What I want actually is only the modifications(insert/update/delete) on certain database tables in the schema. In such a case would auditing be helpful ?

sgalaxy

I think auditing is going to capture all the records being run in the database

It depends. If you want all then all are registered.

Auditing allows registering actions - for example:

1) at the session level, whatever a db user does.

2) at a/some objects owned by a db user and a/some operations(for example dml operations).

e.t.c.

You can consult the Oracle doc:

http://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_4007.htm#SQLRF01107

https://docs.oracle.com/cd/B16240_01/doc/install.102/e12914/ap_oracle_database_auditing.htm  <some examples>

Auditing may be used only to catch the dml operations on tables{sql scripts}.

Greetings

Martin Preiss

if you just want to replicate the data of table x in database 1 to a corresponding object in database 2 then you could create a materialized view in database 2 accessing table x in database 1 and refreshing the MV whenever you think it adequate. Tim Hall provides a small example (as usual) in https://oracle-base.com/articles/misc/materialized-views. If you want something different then maybe the MV is not your option: so maybe you could be a little bit more verbose on your actual requirements.

1 - 12
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 8 2015
Added on Sep 9 2015
12 comments
587 views