'Errors unique to Db2 SQL queries
I am using Hacker Rank to learn SQL sufficiently to pass coding interviews.
I have noticed an error in the online compiler when I run it using DB2. In Oracle, MS MS SQL SERVER, or MySQL no error is produced.
The following code is the solution to the problem posted above.
SELECT *
FROM City
WHERE Countrycode = 'JPN';
It returns the following in everything except in Db2:
1613 Neyagawa JPN Osaka 257315
1630 Ageo JPN Saitama 209442
1661 Sayama JPN Saitama 162472
1681 Omuta JPN Fukuoka 142889
1739 Tokuyama JPN Yamaguchi 107078
But for some reason using DB2 it returns the solution and then an error message:
1613 Neyagawa JPN Osaka 257315
1630 Ageo JPN Saitama 209442
1661 Sayama JPN Saitama 162472
1681 Omuta JPN Fukuoka 142889
1739 Tokuyama JPN Yamaguchi 107078
DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "database" was found following "k line. */ uncatalog". Expected tokens may include: "JOIN <joined_table>".
SQLSTATE=42601
How widely used is Db2? How can I avoid this error?
Solution 1:[1]
This error prompts when database is not cataloged. Db2 requires catalog to get the correct answer. You check if database is cataloged in the local directory and run the program. On hackerrank we cannot check the db so it gives error.
Solution 2:[2]
I was just doing the exact same thing, and it turned out I just needed to add the ';' at the end of the line, as the instructions state. Coming from python, I forgot
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Sanyogita Waykar |
Solution 2 | Nesha25 |