How to check Create Table SQl query in DBFit?

239 Views Asked by At

I have created a table using sqlplus without any data. How can I write a test in DBFit to check if a table with that name exists?

3

There are 3 best solutions below

0
APC On

So you want an assertion that the table exists. Simply a matter of checking of the Oracle data dictionary.

Without knowing DBfit syntax the query would be:

select count(*) 
from user_tables
where table_name = 'YOUR_TEST_TABLE';

If that returns 1 the table exists with that name. If 0 it doesn't.

0
Niraj Sonawane On

you can use Query Stats for this.

syntax is like this.

!| Query  Stats |  
|   query     |    is empty?|

|select * from user_tables where table_name = 'table_name'         |false          |
1
Joe C On

Following the answer from APC, in DBFIt you would do something like this:

!|Query| !- select count(*) KNT
from user_tables
where table_name = 'YOUR_TEST_TABLE' -!|
|KNT|
|1|

Although, if its not a table of your creation, you may wish to use all_tables instead of user_tables.