調用存儲過程db2
A. 在C#NET中怎樣調用db2存儲過程
1、找開sql server 2005,創建表名為abc的表,表的設計如圖。 2、給表中加入三行數據,如圖。 3、創建一個名為「pro_abc」的存儲過程,內容如圖。 4、在程序中的配置文件,配置資料庫鏈接字元串,如圖。
B. db2 調用存儲過程,報錯:SQL1646N 無法訪問sqllib
幫一下包試試?
db2 terminate
db2 CONNECT TO dbname user USERID using PASSWORD
db2 BIND path\db2schema.bnd BLOCKING ALL GRANT PUBLIC SQLERROR CONTINUE
db2 BIND path\@db2ubind.lst BLOCKING ALL GRANT PUBLIC ACTION ADD
db2 BIND path\@db2cli.lst BLOCKING ALL GRANT PUBLIC ACTION ADD
db2 terminate
where dbname represents the name of a database to which the files should be bound, and where path is the full path name of the directory where the bind files are located, such as INSTHOME\sqllib\bnd where INSTHOME represents the home directory of the DB2 instance. db2ubind.lst and db2cli.lst contain lists of required bind files used by DB2 database procts. Packages that are already bound will return an SQL0719N error. This is expected.
C. DB2存儲過程
db2 -td@ -vf a.db2
這一句中@的意思是讀取文件中的分隔,每遇到一個@號會將之前的SQL語句做為單獨一段來執行,你的存儲過程中有使用了這個符號,則執行時將創建存儲過程的語句給分拆開了,所以執行會同語法錯誤,你這一段中只需要兩個@號,第一句連接資料庫後用一個,最後用一個,中間的改成「;」號。
connect to toolsdb@
CREATE PROCEDURE testProced(
in in_name varchar(20),
out out_name varchar(20)
)
LANGUAGE SQL
BEGIN
select a into out_name from bb where a1 = in_name;
END@