DB2执行SQL语句如何才不会报错呢?这是很多人都提到过的问题,下面就就教您DB2执行SQL语句并导出表记录的实现方法,供您参考。
为企业提供成都做网站、网站建设、网站优化、成都营销网站建设、竞价托管、品牌运营等营销获客服务。创新互联公司拥有网络营销运营团队,以丰富的互联网营销经验助力企业精准获客,真正落地解决中小企业营销获客难题,做到“让获客更简单”。自创立至今,成功用技术实力解决了企业“网站建设、网络品牌塑造、网络营销”三大难题,同时降低了营销成本,提高了有效客户转化率,获得了众多企业客户的高度认可!
很多人在console写DB2 SQL语句的时候习惯性的按enter换行,结果语句就直接执行报错.这是因为DB2默认的分隔符是空格,
如果要换行写语句,就必须在每行语句结尾加\,\表示换行.
还有一个写法就是连接DB2后,输入命令db2 -t, 这样就不需每行语句结尾都加\.只需按enter换行,语句写完后输入分号(;) 提交语句运行.
推荐使用下面的方式在DB2执行SQL语句并导出表记录.
- JXBI_js1:/db2home/mart796>touch crw.txt
- JXBI_js1:/db2home/mart796>db2 CONNECT TO jxmart USER ***** USING ******
- Database Connection Information
- Database server = DB2/AIX64 8.2.5
- SQL authorization ID = MART796
- Local database alias = JXMART
- ###db -t 命令指示语句允许换行,以分号;作结束符###
- JXBI_js1:/db2home/mart796>db2 -t
- (c) Copyright IBM Corporation 1993,2002
- Command Line Processor for DB2 SDK 8.2.5
- You can issue database manager commands and SQL statements from the command
- prompt. For example:
- db2 => connect to sample
- db2 => bind sample.bnd
- For general help, type: ?.
- For command help, type: ? command, where command can be
- the first few keywords of a database manager command. For example:
- ? CATALOG DATABASE for help on the CATALOG DATABASE command
- ? CATALOG for help on all of the CATALOG commands.
- To exit db2 interactive mode, type QUIT at the command prompt. Outside
- interactive mode, all commands must be prefixed with 'db2'.
- To list the current command option settings, type LIST COMMAND OPTIONS.
- For more detailed help, refer to the Online Reference Manual.
- db2 => EXPORT TO "/db2home/mart796/crw.txt" OF DEL MODIFIED BY coldel0x09
- db2 (cont.) => SELECT RN_USER_ID,
- db2 (cont.) => HIS_USER_ID,
- db2 (cont.) => RN_USER_NUMBER,
- db2 (cont.) => HIS_USER_NUMBER,
- db2 (cont.) => RN_BASE_COUNTY_CODE,
- db2 (cont.) => RN_BASE_PLAN_ID,
- db2 (cont.) => RN_CREATE_DATE
- db2 (cont.) => FROM JA.MARTD_DMRN_USER_MS
- db2 (cont.) => WHERE RN_DATE = '2008-07-01'
- db2 (cont.) => ;
- SQL3104N The Export utility is beginning to export data to file
- "/db2home/mart796/crw.txt".
- SQL3105N The Export utility has finished exporting "554848" rows.
- Number of rows exported: 554848
- db2 => quit;
- DB20000I The QUIT command completed successfully.
到此,总共导出584848条记录.接下来的便是把记录get 下来,导入到本地的ORACLE数据库.比较简单.
【编辑推荐】
DB2 CREATE SERVER语句的用法
常用的DB2管理命令
深入探讨DB2表连接原理
几种常用的DB2循环用法
DB2创建数据库的实现
本文名称:DB2执行SQL语句并导出表记录的实现方法
分享URL:http://www.csdahua.cn/qtweb/news34/150384.html
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网