Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

You can use the command line interface to execute a single SQL statement:

Code Block
languagenone
./> dbviscmd.shbat -connection "Oracle" -sql "select * from hr.countries"
select * from hr.countries;
INFO: 14:20:31  [SELECT - 25 row(s), 0.247 secs] Result set fetched
COUNTRY_ID  COUNTRY_NAME              REGION_ID  
----------  ------------------------  ---------  
AR          Argentina                 2          
AU          Australia                 3          
BE          Belgium                   1          
BR          Brazil                    2          
CA          Canada                    2          
CH          Switzerland               1          
CN          China                     3          
DE          Germany                   1          
DK          Denmark                   1          
EG          Egypt                     4          
FR          France                    1          
HK          HongKong                  3          
IL          Israel                    4          
IN          India                     3          
IT          Italy                     1          
JP          Japan                     3          
KW          Kuwait                    4          
MX          Mexico                    2          
NG          Nigeria                   4          
NL          Netherlands               1          
SG          Singapore                 3          
UK          United Kingdom            1          
US          United States of America  2          
ZM          Zambia                    4          
ZW          Zimbabwe                  4          
SUMMARY: ... 1 statement(s) executed, 25 row(s) affected, exec/fetch time: 0.247/0.002 sec
 [1 successful, 0 warnings, 0 errors]

If you like to execute just a few statements, you can pass in a list of statements:

Code Block
languagenone
./> dbviscmd.shbat -connection "Oracle" -sql "select * from hr.countries; select * from hr.regions"
select * from hr.countries;
INFO: 14:23:39  [SELECT - 25 row(s), 0.012 secs] Result set fetched
COUNTRY_ID  COUNTRY_NAME              REGION_ID  
----------  ------------------------  ---------  
AR          Argentina                 2          
AU          Australia                 3          
BE          Belgium                   1          
BR          Brazil                    2          
CA          Canada                    2          
CH          Switzerland               1          
CN          China                     3          
DE          Germany                   1          
DK          Denmark                   1          
EG          Egypt                     4          
FR          France                    1          
HK          HongKong                  3          
IL          Israel                    4          
IN          India                     3          
IT          Italy                     1          
JP          Japan                     3          
KW          Kuwait                    4          
MX          Mexico                    2          
NG          Nigeria                   4          
NL          Netherlands               1          
SG          Singapore                 3          
UK          United Kingdom            1          
US          United States of America  2          
ZM          Zambia                    4          
ZW          Zimbabwe                  4          
select * from hr.regions;
INFO: 14:23:39  [SELECT - 4 row(s), 0.130 secs] Result set fetched
REGION_ID  REGION_NAME             
---------  ----------------------  
1          Europe                  
2          Americas                
3          Asia                    
4          Middle East and Africa  
SUMMARY: ... 2 statement(s) executed, 29 row(s) affected, exec/fetch time: 0.142/0.003 sec
 [2 successful, 0 warnings, 0 errors]

...

If you frequently want to execute a number of statements, it's best to put them into a script file. Here's how to execute a script that contains the two statements from the example above:

Code Block
languagenone
./> dbviscmd.shbat -connection "Oracle" -sqlfile "myscript.sql"
select * from hr.countries;
INFO: 16:38:06  [SELECT - 25 row(s), 0.021 secs] Result set fetched
COUNTRY_ID  COUNTRY_NAME              REGION_ID  
----------  ------------------------  ---------  
AR          Argentina                 2          
AU          Australia                 3          
BE          Belgium                   1          
BR          Brazil                    2          
CA          Canada                    2          
CH          Switzerland               1          
CN          China                     3          
DE          Germany                   1          
DK          Denmark                   1          
EG          Egypt                     4          
FR          France                    1          
HK          HongKong                  3          
IL          Israel                    4          
IN          India                     3          
IT          Italy                     1          
JP          Japan                     3          
KW          Kuwait                    4          
MX          Mexico                    2          
NG          Nigeria                   4          
NL          Netherlands               1          
SG          Singapore                 3          
UK          United Kingdom            1          
US          United States of America  2          
ZM          Zambia                    4          
ZW          Zimbabwe                  4          
select * from hr.regions;
INFO: 16:38:06  [SELECT - 4 row(s), 0.005 secs] Result set fetched
REGION_ID  REGION_NAME             
---------  ----------------------  
1          Europe                  
2          Americas                
3          Asia                    
4          Middle East and Africa  
SUMMARY: ... 2 statement(s) executed, 29 row(s) affected, exec/fetch time: 0.026/0.001 sec
 [2 successful, 0 warnings, 0 errors]

...

You can use options to control how much output to generate. If you only want to see the results, use the -output option with the result keyword:

Code Block
languagenone
./> dbviscmd.shbat -connection "Oracle" -sqlfile "myscript.sql" -output result
COUNTRY_ID  COUNTRY_NAME              REGION_ID  
----------  ------------------------  ---------  
AR          Argentina                 2          
AU          Australia                 3          
BE          Belgium                   1          
BR          Brazil                    2          
CA          Canada                    2          
CH          Switzerland               1          
CN          China                     3          
DE          Germany                   1          
DK          Denmark                   1          
EG          Egypt                     4          
FR          France                    1          
HK          HongKong                  3          
IL          Israel                    4          
IN          India                     3          
IT          Italy                     1          
JP          Japan                     3          
KW          Kuwait                    4          
MX          Mexico                    2          
NG          Nigeria                   4          
NL          Netherlands               1          
SG          Singapore                 3          
UK          United Kingdom            1          
US          United States of America  2          
ZM          Zambia                    4          
ZW          Zimbabwe                  4          
REGION_ID  REGION_NAME             
---------  ----------------------  
1          Europe                  
2          Americas                
3          Asia                    
4          Middle East and Africa  

For other scripts, for instance a script containing INSERT statements, you may only want to see the log messages:

Code Block
languagenone
./> dbviscmd.shbat -connection "Oracle" -sqlfile "myscript.sql" -output log
select * from hr.countries;
INFO: 16:52:56  [SELECT - 25 row(s), 0.013 secs] Result set fetched
select * from hr.regions;
INFO: 16:52:56  [SELECT - 4 row(s), 0.002 secs] Result set fetched
SUMMARY: ... 2 statement(s) executed, 29 row(s) affected, exec/fetch time: 0.015/0.002 sec
 [2 successful, 0 warnings, 0 errors]

...