Hello World (SQL)

From LiteratePrograms

Jump to: navigation, search
Other implementations: Ada | ALGOL 68 | Alice ML | Amiga E | Applescript | AspectJ | Assembly Intel x86 Linux | Assembly Intel x86 NetBSD | AWK | bash | BASIC | Batch files | C | C, Cairo | C, Xlib | Candle | Clojure | C++ | C# | Delphi | Dylan | E | Eiffel | Erlang | Forth | FORTRAN | Fortress | Go | Groovy | Haskell | Hume | IBM PC bootstrap | Inform 7 | Java | Java, Swing | JavaScript | LaTeX | Lisp | Logo | Lua | Maple | MATLAB | Mercury | OCaml/F Sharp | occam | Oz | Pascal | Perl | PHP | Pic | PIR | PLI | PostScript | Prolog | Python | Rexx | Ruby | Scala | Scheme | Seed7 | sh | Smalltalk | SQL | Standard ML | SVG | Tcl | Tcl Tk | Visual Basic | Visual Basic .NET | XSL

In many SQL databases, you may return 'Hello, World!' by simply stating:

<<hello.sql>>=
SELECT 'Hello, World!';

However, the above code is actually not correct, according to the ISO SQL standard. To be correct, you must include a FROM specification, or use the VALUES construct which is an optional standard SQL feature:

Assuming that the table called foo has one single row, and a column called somecol, containing the 'Hello, World!' string:

<<hello_standard_1.sql>>=
SELECT somecol FROM foo;

- Or, assuming that the database implements the optional VALUES construct (feature ID F641, “Row and table constructors”):

<<hello_standard_2.sql>>=
VALUES('Hello, World!');

The Oracle DBMS requires one to select from some table. We can use the Oracle-specific dummy table "DUAL" which contains only one row:

<<hello_oracle.sql>>=
SELECT 'Hello, World!' FROM dual;
Download code
Views