What's the SQL format for Db2 on IBM Cloud?

℡╲_俬逩灬. 提交于 2021-01-29 17:30:41

问题


I'm using the free version of Db2 on IBM Cloud. I want to use it in Spring Boot application with JDBC driver. But I don't know what's the SQL format for the Db2 on IBM Cloud. The official documents are somewhat clutter. I have googled but can't find a tutorial.

I have the following SQL that works with H2 database. I want to translate to Db2 on IBM Cloud's SQL format. I have searched some SQL dialect translators like this one: https://www.jooq.org/translate/ But it seems not work for the IBM Cloud format.

DROP TABLE IF EXISTS id_0065_00000004;

CREATE TABLE IF NOT Exists id_0065_00000004 (
 gmeid           VARCHAR(16) NOT NULL,
 businessid      VARCHAR(25) NOT NULL,
 businesssubid   VARCHAR(25) NOT NULL,
 kind            VARCHAR(25) ,
 name            VARCHAR(255) ,
 kindvalue       VARCHAR(255) ,
 kindtype        VARCHAR(20) ,
 securitycode    VARCHAR(25) ,
 flowcode        VARCHAR(12) ,
 flowsubcode     VARCHAR(12) ,
 startdate       DATE      NOT NULL,
 enddate         DATE      NOT NULL,
 withdrawaldate  DATE     NOT NULL,
 orientationkey  VARCHAR(500) ,
 parentid        VARCHAR(16) ,
 createdate      DATE,
 createuser      VARCHAR(25) ,
 updatedate      DATE,
 updateuser      VARCHAR(25) ,
 lockflg         BIT,
 lockuser        VARCHAR(25) ,
 lockdate        DATE,
 updatemachine   VARCHAR(25) ,
 PRIMARY KEY (businessid, gmeid, businesssubid)
);

CREATE INDEX kind ON id_0065_00000004(kind);

So how do I convert the above SQL to DB2 format?


回答1:


Not sure what you exactly mean. Db2 on Cloud has a download page for the correct JDBC driver and instructions on how to connect to Db2. Db2 on Cloud is a managed service based on IBM Db2 (for Linux, Windows and UNIX).

Here is a tutorial for regular Db2 and Spring. Most wrappers support Db2 out of the box.

In the case that you are interested in the actual SQL syntax, there is a link SQL Reference on the actual doc portal for Db2 on Cloud.




回答2:


Change

lockflg         BIT,

to

lockflg         BOOLEAN,

and as @mao points out the IF EXIST and IF NOT EXIST require 11.5



来源:https://stackoverflow.com/questions/57221628/whats-the-sql-format-for-db2-on-ibm-cloud

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!