Reputation: 16646
Previously we used DB2 as database, but now we are migrating to Oracle. Now, in our project we have extensively used sql's that were Db2 specific.
Is there any way to convert those DB2 specific queries to oracle supported queries.
Thanks
Upvotes: 2
Views: 10585
Reputation: 220932
You have a lot of work ahead!
Between DB2 and Oracle, some important differences are (just an arbitrary enumeration of what I can think of):
SMALLINT
, INTEGER
, DOUBLE
, etc. Those don't exist in Oracle SQL (although some exist in PL/SQL). This is important for DDL and for casting and some other use cases, such as the correctness of predicatesDATE
and TIMESTAMP
is the fact that TIMESTAMP
has microseconds. But DATE
may also contain time information. In DB2, DATE
has no time information, I think.VARCHAR
and VARCHAR2
in OracleNULL
. In Oracle, NULL
is much more general than in DB2. Before DB2 v9.7, you had to cast NULL
to any explicit type, e.g. cast(null as integer)
. That's not necessary in Oracle.SYSIBM.DUAL
simply becomes DUAL
LOCATE
becomes INSTR
TRUNCATE IMMEDIATE
becomes TRUNCATE
EXCEPT
becomes MINUS
FETCH FIRST n ROWS ONLY
: There is no such clause in Oracle. You'll have to use ROWNUM
or ROW_NUMBER() OVER()
filtering (see this example)MERGE
statement is more powerful than that of Oracle, in case you use this.INSERT INTO .. (..) VALUES (..), (..), (..)
. With Oracle, you'd have to write INSERT INTO .. SELECT .. UNION ALL SELECT .. UNION ALL SELECT ..
Your most efficient shot at this might be to use SQL abstraction of some sort. If you're using Java, I would recommend you wrap your SQL statements with jOOQ (Disclaimer: I work for the company behind jOOQ). jOOQ provides API-level abstraction for all of the above facts. A great deal of SQL can be executed both on DB2 and Oracle, without adaptation. We're also working on a more independent translator product: https://www.jooq.org/translate
On a higher level of abstraction, Hibernate (or other JPA implementations) can do the same for you
Upvotes: 3
Reputation: 1
I found out that there are also some differences in the management of character strings.
DB2 doesn't care about the trailing whitespaces when comparing:
/* DB2 */
SELECT CASE WHEN ('A ' = 'A') THEN 'true' ELSE 'false' END FROM SYSIBM.SYSDUMMY1
--> true
/* Oracle */
SELECT CASE WHEN ('A ' = 'A') THEN 'true' ELSE 'false' END FROM DUAL
--> false
Oracle considers that ''
equals NULL
:
/* DB2 */
SELECT CASE WHEN ('' IS NULL) THEN 'true' ELSE 'false' END FROM SYSIBM.SYSDUMMY1
--> false
/* Oracle */
SELECT CASE WHEN ('' IS NULL) THEN 'true' ELSE 'false' END FROM DUAL
--> true
Upvotes: 0