I need some help in writing a PL SQL program to generate dynamic SQL queries for all tables in a schema which does self join on the Primary key of each table .
We have 100s of tables in a schema and each table has its own composite primary key, we would like to generate queries for every table each doing self join to its own on the primary key (every tables pk has a incremental seq no which I would like to ignore)
E.g.:
Table CUSTOMER has Primary key on CUST_ID, CUST_DEPT,CUST_CD
would like to generate a PL SQL block which would generate a query doing self join as below for all the tables each on its own primary key
SELECT CUST1.* FROM CUSTOMER CUST1,CUSTOMER CUST 2
WHERE
CUST1.CUST_ID=CUST2.CUST_ID
AND
CUST1.CUST_DEPT=CUST2.CUST_DEPT
AND
CUST1.CUST_CD=CUST2.CUST_CD
AND CUST1.record_cd<>'D'
every table has a incremental sequence number also as part of key which is the reason why I ignore it in my self join.
Biddings are invited
Hello Sir,
I am interested in writing this PL/SQL. I am an expert SQL developer and understand the complexity involved in this sql. I believe the end result you need is PL/SQL which in turn will generate SQL similar to as mentioned in the job posting.
Thanks
Aanvik