Suppressing Headers while using DB2CLI

633 views Asked by At

While using DB2CLI command,we get IBM copyright information and footer details. Is there any option to suppress header and footer information ?

echo "select CURRENT USER from dual"|db2cli execsql -dsn 'SAMPLE'

Output

PS C:\Users\Desktop> echo "select CURRENT USER from dual"|db2cli execsql -dsn 'SAMPLE'
IBM DATABASE 2 Interactive CLI Sample Program
(C) COPYRIGHT International Business Machines Corp. 1993,1996
All Rights Reserved
Licensed Materials - Property of IBM
US Government Users Restricted Rights - Use, duplication or
disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
> select CURRENT USER from dual
FetchAll:  Columns: 1
  1 
  TESTUSER 
FetchAll: 1 rows fetched.
>

Tried using set headers=off,which usually works in jsqsh but it doesn't work with DB2CLI,any leads are appreciated.

2

There are 2 answers

1
mao On

There is no documented way to do this with the db2cli tool for currently shipping Db2-LUW versions up to V11.5.

There may be undocumented methods that IBM staff/contractors may disclose.

The tool db2cli is not intended as a general purpose SQL interface, instead it is for troubleshooting, verification, configuration, simple testing and also debugging.

Alternatives include:

  • post-processing scripts to strip off anything you don't want, but you have to write these,

  • use a Db2-client that includes the db2 CLP which lets you use its -x option (among other options) and does not issue a copyright string. The Db2 Runtime client is small footprint and includes the db2 CLP.

  • use a scripting interface to Db2 (python, perl, bash) or a programmatic interface (c#, or other .net language) so you are in control, but these require relevant configuration.

0
data_henrik On

You may want to take a look at the tool db2batch. It allows to send SQL to Db2 and retrieve the results.

If you want full control, then go with what mao suggested in the other answer.