这是我用来创建存储过程的内容,该存储过程显示了来自客户的详细信息,其中cus_ID = CustomerID参数。
p <- structure(list(study = structure(c(12L, 2L, 12L, 12L, 9L, 8L,
13L, 2L, 12L, 15L, 1L, 13L, 2L, 12L, 9L, 16L, 8L, 3L, 5L, 13L,
11L, 5L, 4L, 6L, 1L, 9L, 4L, 12L, 1L, 8L, 12L, 11L, 4L, 2L, 6L,
3L, 12L, 4L, 5L, 8L, 12L, 12L, 5L, 12L, 4L, 13L, 12L, 10L, 4L,
12L), .Label = c("1", "2", "3", "4", "5", "6", "7", "8", "9",
"10", "11", "12", "13", "14", "15", "22"), class = "factor"),
response = c("3", "3", "3", "4", "3", "1", "4", "3", "3",
"4", "4", "4", "3", "3", "2", "4", "1", "3", "3", "4", "4",
"2", "3", "3", "3", "2", "4", "3", "4", "1", "4", "4", "3",
"3", "4", "3", "3", "3", "2", "1", "4", "4", "3", "3", "4",
"4", "3", "4", "4", "3"), treatment = structure(c(2L, 1L,
2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L,
1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 2L,
1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L,
2L, 1L, 2L), .Label = c("SSTR", "SSA"), class = "factor")), row.names = c(NA,
-50L), class = "data.frame")
我一直遇到的错误是
Create procedure getCusDetails (IN CustomerID int) \
BEGIN \
DECLARE c cursor with return for \
SELECT *from customer \
where cus_ID = CustomerID \
OPEN C \
END
我该如何解决?
答案 0 :(得分:1)
您需要正确的定界符,既要在过程内部定界每个语句,又要使用不同的终止符来结束程序段。
您似乎正在使用命令行外壳程序,这使其变得更加困难。如果将语句放入文件(或shell脚本中的here文档),然后要求Db2 clp执行文件{here}或db2 -tvf yourfile.sql
,则更容易编译存储过程。
db2 -tvf << EndHereDocument .... EndHereDocument
以下示例显示了文件内容,该文件内容使用了块内的默认定界符(半冒号;),以及使用不同的定界符@结束了块。
--#SET TERMINATOR @
Create procedure getCusDetails (IN CustomerID int)
BEGIN
DECLARE c cursor with return for SELECT *from customer where cus_ID = CustomerID ;
OPEN C ;
END@