Aliases in unix are used to make it easier to run commands that are long or hard to remember. Below is an example of how to create an alias to run DB2 SQL
alias db2='function _db2(){ echo "Running $1"; system -i "call QSYS/QZDFMDB2 parm('\''$1'\'')"; };_db2' | |
db2 "SELECT * FROM MYLIB.MYTABLE" | |
#Get fancy and search the data | |
db2 "SELECT * FROM MYLIB.MYTABLE" | grep "Smith" | |
#Alternatively you can run it through qsh – https://kadler.github.io/2018/05/29/calling-qsh-utilities-from-pase.html |
WARNING! – This is just an experiment and you might want to add some security to this to make sure that sql injection and other things don’t occur.
Shout out to @tweetjbh https://twitter.com/tweetjbh for the ideas!
Used this today. Thanks for sharing.
Awesome! Glad it worked for you!
It’s a great tip!
You can also do something like:
qsh -c ‘db2 “SELECT * FROM MYLIB.MYTABLE” ‘ |grep “Smith”
The good thing with DB2 CLI on QSHELL is the ability to run really large SQL scripts, even with CR/LF .
Thanks Diego! I’ll have to try that out!