免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4066 | 回复: 7
打印 上一主题 下一主题

关于存储过程的创建,求助!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2002-12-22 09:39 |只看该作者 |倒序浏览
我在Stored Procedure Builder中建好了一个存储过程,代码如下:
CREATE PROCEDURE DB2ADMIN.Proc1 (  )
    LANGUAGE SQL
------------------------------------------------------------------------
-- SQL Stored Procedure
------------------------------------------------------------------------
BEGIN

   create table zhouhaiming(
   f1 smallint,
   f2 varchar(9),
   f3 char(5)
   )&#59;
   insert into zhouhaiming values
   (1,'www','aaa')&#59;
END @  
输入窗口显示
DB2ADMIN.PROC1 - Create stored procedure returns -778.

DB2ADMIN.PROC1: 15: [IBM][CLI Driver][DB2/NT] SQL0778N  End label "@" is not the same as the begin label.  LINE NUMBER=15.  SQLSTATE=428D5



DB2ADMIN.PROC1 - Build failed.

DB2ADMIN.PROC1 - Changes rolled back.
去掉END后的@,再build,输出窗口显示
DB2ADMIN.PROC1 - Create stored procedure returns -778.

DB2ADMIN.PROC1: 15: [IBM][CLI Driver][DB2/NT] SQL0778N  End label "@" is not the same as the begin label.  LINE NUMBER=15.  SQLSTATE=428D5



DB2ADMIN.PROC1 - Build failed.

DB2ADMIN.PROC1 - Changes rolled back.
我在Build存储过程以前已经在CLP环境下设好了下列参数,并且已经安装了VC++6.0,也重启了DB2
db2set DB2_SQLROUTINE_COMPILER_PATH="c:\progra~1\micros~4\vc98\bin\vcvars32.bat"
db2set DB2_SQLROUTINE_KEEP_FILES=1
按照资料的说法我没有设DB2_SQLROUTINE_COMPILE_COMMAND参数,用默认值即可

哪位高手能告诉我,为什么我不能创建存储过程吗?

论坛徽章:
0
2 [报告]
发表于 2002-12-22 13:50 |只看该作者

关于存储过程的创建,求助!!

  你把开始和结束的语句修改一下
------------------------------------------------------------------------
-- SQL Stored Procedure
------------------------------------------------------------------------
p1:BEGIN
...
...
...
end p1

论坛徽章:
0
3 [报告]
发表于 2002-12-22 18:53 |只看该作者

关于存储过程的创建,求助!!

把程序改为
CREATE PROCEDURE DB2ADMIN.Proc1 (  )
    LANGUAGE SQL
------------------------------------------------------------------------
-- SQL Stored Procedure
------------------------------------------------------------------------
P1: BEGIN
create table zhouhaiming(
  f1 smallint,
  f2 varchar(9),
  f3 char(5)
  )&#59;
  insert into zhouhaiming values
  (1,'www','aaa')&#59;



END P1                              

执行Build后输出窗口显示如下
DB2ADMIN.PROC1 - Create stored procedure returns -7032.

DB2ADMIN.PROC1: [IBM][CLI Driver][DB2/NT] SQL7032N  SQL procedure &quotROC1" not created.  Diagnostic file is &quot3413010.log".  SQLSTATE=42904



DB2ADMIN.PROC1 - Build failed.

DB2ADMIN.PROC1 - Changes rolled back.


打开P3413010.log文件,如下


*** PREPCOMPILE C:\PROGRA~1\SQLLIB\function\routine\sqlproc\DEVELOP\DB2ADMIN\tmp\P3413010.sqc ***

LINE    MESSAGES FOR P3413010.sqc
------  --------------------------------------------------------------------
        SQL0060W  The "C" precompiler is in progress.
  148   SQL0204N  "DB2ADMIN.ZHOUHAIMING" is an undefined name.
        SQL0091W  Precompilation or binding was ended with "0"
                  errors and "1" warnings.

*** COMPILE C:\PROGRA~1\SQLLIB\function\routine\sqlproc\DEVELOP\DB2ADMIN\tmp\P3413010.c ***


@echo off
REM set VCV6_DRIVE=c:\Microsoft Visual Studio
REM set include=%include%&#59;%VCV6_DRIVE%\VC98\atl\include&#59;%VCV6_DRIVE%\VC98\mfc\include&#59;%VCV6_DRIVE%\VC98\include
REM set lib=%lib%&#59;%VCV6_DRIVE%\VC98\mfc\lib&#59;%VCV6_DRIVE%\VC98\lib
REM set path=%path%&#59;%VCV6_DRIVE%\Common\Tools\WinNT&#59;%VCV6_DRIVE%\Common\MSDev98\Bin&#59;%VCV6_DRIVE%\Common\Tools&#59;%VCV6_DRIVE%\VC98\bin&#59;%VCV6_DRIVE%\VC98\mfc\lib&#59;%VCV6_DRIVE%\VC98\lib

@echo off
REM set VCV5_DRIVE=c:\Program Files\devstudio
REM set include=%include%&#59;%VCV5_DRIVE%\vc\include&#59;%VCV5_DRIVE%\vc\atl\include&#59;%VCV5_DRIVE%\vc\mfc\include
REM set lib=%lib%&#59;%VCV5_DRIVE%\vc\lib&#59;%VCV5_DRIVE%\vc\mfc\lib
REM set path=%path%&#59;%VCV5_DRIVE%\sharedide\bin\ide&#59;%VCV5_DRIVE%\sharedide\bin&#59;%VCV5_DRIVE%\vc\bin


@echo on
set SQLROUTINE_FILENAME=P3413010
set db2path=C:\PROGRA~1\SQLLIB

nmake /f C:\PROGRA~1\SQLLIB\function\routine\sqlproc.mak

*** C:\PROGRA~1\SQLLIB\function\routine\sqlproc\DEVELOP\DB2ADMIN\tmp\P3413010.def ***
LIBRARY P3413010
EXPORTS _pgsjmp@4
pgsjmp=_pgsjmp@4


C:\PROGRA~1\SQLLIB\function\routine\sqlproc\DEVELOP\DB2ADMIN\tmp>;set SQLROUTINE_FILENAME=P3413010

C:\PROGRA~1\SQLLIB\function\routine\sqlproc\DEVELOP\DB2ADMIN\tmp>;set db2path=C:\PROGRA~1\SQLLIB

C:\PROGRA~1\SQLLIB\function\routine\sqlproc\DEVELOP\DB2ADMIN\tmp>;nmake /f C:\PROGRA~1\SQLLIB\function\routine\sqlproc.mak

'nmake' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

----------------------------------------------------------------------------

SQL7032N  SQL procedure &quotROC1" not created.  Diagnostic file is
&quot3413010.log".  SQLSTATE=42904

论坛徽章:
0
4 [报告]
发表于 2002-12-22 18:58 |只看该作者

关于存储过程的创建,求助!!

我用db2 ? SQL7032N查看了一下错误内容,系统显示
SQL7032N SQL procedure &quot;<procedure-name>;&quot; not created.
          Diagnostic file is &quot;<file-name>;&quot;.

Explanation:  SQL Procedure &quot;<procedure-name>;&quot; was not created.
One of the following has occurred:

o   Support for SQL stored procedures is not installed and
    configured on this server. You need to have the DB2
    Application Development Client and a C compiler installed on
    the server to create SQL procedures.  You may need to set the
    DB2 registry variable DB2_SQLROUTINE_COMPILER_PATH to point
    to a script or batch file that contains environment settings
    for the C compiler on your platform.

o   DB2 failed to precompile or compile the SQL stored procedure.
    DB2 creates an SQL procedure as a C program that contains
    embedded SQL. Errors not found during the inital parsing of
    the CREATE PROCEDURE statement can be found during the
    precompile or compile stage.

For UNIX platforms, the full path of the file that contains
diagnostic information is:

$DB2PATH/function/routine/sqlproc/ \
$DATABASE/$SCHEMA/tmp/&quot;<file-name>;&quot;where $DATABASE represents the
name of the database, and $SCHEMA represents the schema name of
the SQL procedure.

For OS/2 and Windows 32-bit operating systems, the full path of
the file that contains diagnostic information is:

%DB2PATH%\function\routine\sqlproc\ \
%DATABASE%\%SCHEMA%\tmp\&quot;<file-name>;&quot;where %DATABASE% represents
the name of the database, and %SCHEMA% represents the schema name
of the SQL procedure.

User Response:  Ensure that both a compatible C compiler and a
DB2 Application Development Client are installed on the server.
If a precompile or compile error occurred, refer to the messages
from the precompiler or compiler in the diagnostic file
&quot;<file-name>;&quot;.

Ensure that the DB2 registry variable
DB2_SQLROUTINE_COMPILER_PATH is set to point to a script or batch
file that sets up the C compiler environment.  On a UNIX
operating system, for example, you may create a script called
&quot;sr_cpath&quot; in the /home/DB2INSTANCE/sqllib/function/routine
directory.  To set the DB2 registry variable
DB2_SQL_ROUTINE_COMPILER_PATH accordingly, issue the following
command:

     db2set DB2_SQLROUTINE_COMPILER_PATH = \
        &quot;/home/DB2INSTANCE/sqllib/function/ \
        routine/sr_cpath&quot;

sqlcode:  -7032

sqlstate:  42904


C:\PROGRA~1\SQLLIB\BIN>;db2 ? SQL7032N

SQL7032N SQL procedure &quot;<procedure-name>;&quot; not created.
          Diagnostic file is &quot;<file-name>;&quot;.

Explanation:  SQL Procedure &quot;<procedure-name>;&quot; was not created.
One of the following has occurred:

o   Support for SQL stored procedures is not installed and
    configured on this server. You need to have the DB2
    Application Development Client and a C compiler installed on
    the server to create SQL procedures.  You may need to set the
    DB2 registry variable DB2_SQLROUTINE_COMPILER_PATH to point
    to a script or batch file that contains environment settings
    for the C compiler on your platform.

o   DB2 failed to precompile or compile the SQL stored procedure.
    DB2 creates an SQL procedure as a C program that contains
    embedded SQL. Errors not found during the inital parsing of
    the CREATE PROCEDURE statement can be found during the
    precompile or compile stage.

For UNIX platforms, the full path of the file that contains
diagnostic information is:

$DB2PATH/function/routine/sqlproc/ \
$DATABASE/$SCHEMA/tmp/&quot;<file-name>;&quot;where $DATABASE represents the
name of the database, and $SCHEMA represents the schema name of
the SQL procedure.

For OS/2 and Windows 32-bit operating systems, the full path of
the file that contains diagnostic information is:

%DB2PATH%\function\routine\sqlproc\ \
%DATABASE%\%SCHEMA%\tmp\&quot;<file-name>;&quot;where %DATABASE% represents
the name of the database, and %SCHEMA% represents the schema name
of the SQL procedure.

User Response:  Ensure that both a compatible C compiler and a
DB2 Application Development Client are installed on the server.
If a precompile or compile error occurred, refer to the messages
from the precompiler or compiler in the diagnostic file
&quot;<file-name>;&quot;.

Ensure that the DB2 registry variable
DB2_SQLROUTINE_COMPILER_PATH is set to point to a script or batch
file that sets up the C compiler environment.  On a UNIX
operating system, for example, you may create a script called
&quot;sr_cpath&quot; in the /home/DB2INSTANCE/sqllib/function/routine
directory.  To set the DB2 registry variable
DB2_SQL_ROUTINE_COMPILER_PATH accordingly, issue the following
command:

     db2set DB2_SQLROUTINE_COMPILER_PATH = \
        &quot;/home/DB2INSTANCE/sqllib/function/ \
        routine/sr_cpath&quot;

sqlcode:  -7032

sqlstate:  42904

应该是DB2_SQLROUTINE_COMPILER_PATH设置错误可是我用db2set -all命令查看发现
[e] DB2PATH=C:\Program Files\SQLLIB
DB2_SQLROUTINE_KEEP_FILES=1
DB2_SQLROUTINE_COMPILER_PATH=C:\Progra~1\Micros~4\VC98\Bin\vcvars32.bat
DB2INSTPROF=C:\PROGRAM FILES\SQLLIB
[g] DB2SYSTEM=ZHOUHAIMING
[g] DB2PATH=C:\Program Files\SQLLIB
[g] DB2INSTDEF=DB2
[g] DB2COMM=TCPIP,NPIPE
[g] DB2ADMINSERVER=DB2DAS00

根本没错呀请高手指点!

论坛徽章:
0
5 [报告]
发表于 2002-12-22 19:58 |只看该作者

关于存储过程的创建,求助!!

路径错了

论坛徽章:
0
6 [报告]
发表于 2002-12-22 22:19 |只看该作者

关于存储过程的创建,求助!!

  刚才忘了仔细看你程序了,你的动态语句,应该用动态sql来执行阿
declare stmt varchar(1024)&#59;
set stmt='create table zhouhaiming( f1 smallint, f2 varchar(9), f3 char(5) )'&#59;
prepare s1 from stmt&#59;
execute s1&#59;
set stmt='insert into zhouhaiming values (1,'www','aaa')'&#59;
prepare s1 from stmt&#59;
execute s1&#59;

试试看,有错误再说

论坛徽章:
0
7 [报告]
发表于 2002-12-22 22:27 |只看该作者

关于存储过程的创建,求助!!

在windows下的存储过程的编译在安装好vc++后,需要改变下面的批处理文件的相应路径:
.....\SQLLIB\function\routine\sr_cpath.bat
其实不用安装vc++也是可以的,在安装好db2后有一个选项,注册&quot;VC++附件&quot;,执行就ok了

论坛徽章:
0
8 [报告]
发表于 2002-12-23 13:03 |只看该作者

关于存储过程的创建,求助!!

作个总结,vlife网友说的对要用IBM的Stored Procedure Builder开发SQL存储过程不仅要设置DB2_SQLROUTINE_COMPILER_PATH和DB2_SQLROUTINE_KEEP_FILES,还要编辑DB2数据库服务器上的<db2_install_path>;\function\routine\sr_cpath.bat文件,打开那些注释即可,sr_cpath.bat文件的内容如下:
@echo off
set VCV6_DRIVE=C:\Program Files\Microsoft Visual Studio
set include=%include%&#59;%VCV6_DRIVE%\VC98\atl\include&#59;%VCV6_DRIVE%\VC98\mfc\include&#59;%VCV6_DRIVE%\VC98\include
set lib=%lib%&#59;%VCV6_DRIVE%\VC98\mfc\lib&#59;%VCV6_DRIVE%\VC98\lib
set path=%path%&#59;%VCV6_DRIVE%\Common\Tools\WinNT&#59;%VCV6_DRIVE%\Common\MSDev98\Bin&#59;%VCV6_DRIVE%\Common\Tools&#59;%VCV6_DRIVE%\VC98\bin&#59;%VCV6_DRIVE%\VC98\mfc\lib&#59;%VCV6_DRIVE%\VC98\lib

@echo off
REM set VCV5_DRIVE=c:\Program Files\devstudio
REM set include=%include%&#59;%VCV5_DRIVE%\vc\include&#59;%VCV5_DRIVE%\vc\atl\include&#59;%VCV5_DRIVE%\vc\mfc\include
REM set lib=%lib%&#59;%VCV5_DRIVE%\vc\lib&#59;%VCV5_DRIVE%\vc\mfc\lib
REM set path=%path%&#59;%VCV5_DRIVE%\sharedide\bin\ide&#59;%VCV5_DRIVE%\sharedide\bin&#59;%VCV5_DRIVE%\vc\bin
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP