工作中公司工程一般都有已經寫好的makefile檔案,并且都比較複雜,以前不知道在linux系統下編譯sql檔案,自己簡單總結了一下:
a.先編寫test.sqc檔案
b.連接配接DB2資料庫,db2 connect to DBNAME user DBUSER using DBPWD
c.使用指令 db2 prep test.sqc BINDFILE package using bndtest,用于生成test.c和test.bnd檔案
d.使用指令 db2 bind test.bnd GRANT PUBLIC 綁定bnd檔案,同時指定通路權限(GRANT PUBLIC)
e.開始編譯 cc -o test test.c -I/home/db2inst1/sqllib/include -L/home/db2inst1/sqllib/lib -ldb2
注:以上5步驟缺一不可,編譯生成執行檔案時候需要找到db2的頭檔案和庫檔案,一般都是在一下兩個目錄
中/home/db2inst1/sqllib/include /home/db2inst1/sqllib/lib -ldb2