![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
| table1 | ''' AS TableName, ' | t1columnlist | ' FROM ' | table1 | ' UNION ALL SELECT ''' | table2 | ''' As TableName, ' | t2columnlist | ' FROM ' | table2; |
|
| t2columnlist | ' FROM (' | sql_stmt | ') A GROUP BY ' | groupby | ' HAVING COUNT(*) = 1'; |
#2
| |||
| |||
|
|
I'm trying to write a stored procedure which will compare two tables dynamically and will display the difference. The input parameter are two table names and columnames(optional) |
|
I get the column names from all_tab_cols table and dynamically form a select statement, when executed will give me the difference between those two tables (using unionall) |
#3
| |||
| |||
|
|
On Feb 23, 2:08*am, Sudhir <nshanmu... (AT) gmail (DOT) com> wrote: I'm trying to write a stored procedure which will compare two tables dynamically and will display the difference. The input parameter are two table names and columnames(optional) Are you comparing the tables DDL or their contents? I get the column names from all_tab_cols table and dynamically form a select statement, when executed will give me the difference between those two tables (using unionall) If you compare the DDL, what you need to do here is create a single query that, given two table names, will output the difference in DDL between them. This question can be answered from xxx_TAB_COL[UMN]S alone. No need for dynamic SQL here as table names are arguments to the query (bind variables.) Actually, it's a very bad idea to concatenate arguments into a dynamic SQL statement like you do instead of using bind variables: not only this approach inhibits scalability, but it opens the door to infamous SQL injection attacks against your code (simply put, I supply SQL as either TABLEA or TABLEB, you blindly concatenate it into your statement and execute that statement executing my code with it. I only need to construct my added SQL in such a way as to form syntactically correct statement from your SQL and my SQL, which is usually pretty simple.) You need to consider how deep the comparison should be - do you only want the names of the columns that do not exist in one of the tables? Or do you also want to identify columns with the same name but different definition (data type?) This will define your GROUP BY clause. You may actually create two different queries answering both questions and add an argument to your SP to choose between them. The purpose of the optional column list is unclear - how is it supposed to constrain the comparison? Regards, * *Vladimir M. Zakharychev * *N-Networks, makers of Dynamic PSP(tm) * *http://www.dynamicpsp.com |
#4
| |||
| |||
|
|
On Feb 23, 3:32*am, "Vladimir M. Zakharychev" vladimir.zakharyc... (AT) gmail (DOT) com> wrote: On Feb 23, 2:08*am, Sudhir <nshanmu... (AT) gmail (DOT) com> wrote: I'm trying to write a stored procedure which will compare two tables dynamically and will display the difference. The input parameter are two table names and columnames(optional) Are you comparing the tables DDL or their contents? I get the column names from all_tab_cols table and dynamically form a select statement, when executed will give me the difference between those two tables (using unionall) If you compare the DDL, what you need to do here is create a single query that, given two table names, will output the difference in DDL between them. This question can be answered from xxx_TAB_COL[UMN]S alone. No need for dynamic SQL here as table names are arguments to the query (bind variables.) Actually, it's a very bad idea to concatenate arguments into a dynamic SQL statement like you do instead of using bind variables: not only this approach inhibits scalability, but it opens the door to infamous SQL injection attacks against your code (simply put, I supply SQL as either TABLEA or TABLEB, you blindly concatenate it into your statement and execute that statement executing my code with it. I only need to construct my added SQL in such a way as to form syntactically correct statement from your SQL and my SQL, which is usually pretty simple.) You need to consider how deep the comparison should be - do you only want the names of the columns that do not exist in one of the tables? Or do you also want to identify columns with the same name but different definition (data type?) This will define your GROUP BY clause. You may actually create two different queries answering both questions and add an argument to your SP to choose between them. The purpose of the optional column list is unclear - how is it supposed to constrain the comparison? Regards, * *Vladimir M. Zakharychev * *N-Networks, makers of Dynamic PSP(tm) * *http://www.dynamicpsp.com I'm trying to compare the contents of two tables. The purpose of the script is compare two tables contents dynamically and display the difference. Actually I'm a tester not developer, my job is to test multiple stored procedures to make sure it works fine for various input. So performance or SQL injection is not a problem. My approach is run the stored procedure under test and write it to Table A. Run the store procedure created by us and write it to Table B. Now I will compare contents of each table, if it matches then test case passed if not the test case fails. If its just a single stored procedure under test then I might have not gone for dynamic approach. We have around 15 stored procedures (many more to come) to test and I thought of having a single stored procedure which will compare tables when I just give the table name alone. On a high level my goal is to automate the store procedure testing during regression. I don't want to manually run each and every testcase(more than 200 testcases) as its time consuming and error prone. |
#5
| |||
| |||
|
|
On Feb 23, 3:32Â*am, "Vladimir M. Zakharychev" vladimir.zakharyc... (AT) gmail (DOT) com> wrote: On Feb 23, 2:08Â*am, Sudhir <nshanmu... (AT) gmail (DOT) com> wrote: I'm trying to write a stored procedure which will compare two tables dynamically and will display the difference. The input parameter are two table names and columnames(optional) Are you comparing the tables DDL or their contents? I get the column names from all_tab_cols table and dynamically form a select statement, when executed will give me the difference between those two tables (using unionall) If you compare the DDL, what you need to do here is create a single query that, given two table names, will output the difference in DDL between them. This question can be answered from xxx_TAB_COL[UMN]S alone. No need for dynamic SQL here as table names are arguments to the query (bind variables.) Actually, it's a very bad idea to concatenate arguments into a dynamic SQL statement like you do instead of using bind variables: not only this approach inhibits scalability, but it opens the door to infamous SQL injection attacks against your code (simply put, I supply SQL as either TABLEA or TABLEB, you blindly concatenate it into your statement and execute that statement executing my code with it. I only need to construct my added SQL in such a way as to form syntactically correct statement from your SQL and my SQL, which is usually pretty simple.) You need to consider how deep the comparison should be - do you only want the names of the columns that do not exist in one of the tables? Or do you also want to identify columns with the same name but different definition (data type?) This will define your GROUP BY clause. You may actually create two different queries answering both questions and add an argument to your SP to choose between them. The purpose of the optional column list is unclear - how is it supposed to constrain the comparison? Regards, Â* Â*Vladimir M. Zakharychev Â* Â*N-Networks, makers of Dynamic PSP(tm) Â* Â*http://www.dynamicpsp.com I'm trying to compare the contents of two tables. The purpose of the script is compare two tables contents dynamically and display the difference. Actually I'm a tester not developer, my job is to test multiple stored procedures to make sure it works fine for various input. So performance or SQL injection is not a problem. My approach is run the stored procedure under test and write it to Table A. Run the store procedure created by us and write it to Table B. Now I will compare contents of each table, if it matches then test case passed if not the test case fails. If its just a single stored procedure under test then I might have not gone for dynamic approach. We have around 15 stored procedures (many more to come) to test and I thought of having a single stored procedure which will compare tables when I just give the table name alone. On a high level my goal is to automate the store procedure testing during regression. I don't want to manually run each and every testcase(more than 200 testcases) as its time consuming and error prone. |
#6
| |||
| |||
|
|
There are some PL/SQL test harnesses that may be worth checking out as well. some are free. Tim |
#7
| |||
| |||
|
|
In article <87pr3v2i3d.... (AT) lion (DOT) rapttech.com.au>, t... (AT) nospam (DOT) dev.null says... There are some PL/SQL test harnesses that may be worth checking out as well. some are free. Tim on automated testing We are looking for automated testing tools or techniques for mod_plsql- based (i.e. web apps powered by pl/sql) applications, can anyone suggest anything? -- jeremy |
#8
| |||
| |||
|
|
On Feb 24, 2:27*am, Jeremy <jeremy0... (AT) gmail (DOT) com> wrote: In article <87pr3v2i3d.... (AT) lion (DOT) rapttech.com.au>, t... (AT) nospam (DOT) dev.null says... There are some PL/SQL test harnesses that may be worth checking out as well. some are free. Tim on automated testing We are looking for automated testing tools or techniques for mod_plsql- based (i.e. web apps powered by pl/sql) applications, can anyone suggest anything? -- jeremy Thanks for all your input. let me check on PL/SQL Unit Testing Framework (utPLSQL) and Quest Code Tester and will keep you all posted. |
![]() |
| Thread Tools | |
| Display Modes | |
| |