Q:

Difference between sql, pl/sql and sqlj

I want to know 

how do the 3 compare with one
another?
which one to use when?
which can be used as a replacement of
other?

A:

SQL -- generic name for the language which is used to query relational databases.
This is governed by various ANSI standards although I know of no actual RDBS which implements completely the latest standard. Several implement most of ANSI SQL - 92 which can be regarded as the lowest common denominator for SQL implementations.
PL/SQL -- An Oracle specific extension to SQL which is used to write "STORED PROCEDURES" and "TRIGGERS" its effectivly a scripting languages which can use Oracles SQL natively. In SQLServer TSQL provides similar functionality.
SQLJ -- Part of the Java standard, a (seldom used) feature which allows SQL to be coded inline with the Java code and for SQL syntax to be checked at compile time. Compare with JDBC which is a standard Java API which allows a Java program to invoke SQL at runtime.

So SQL allows basic querying and updateing of tables as in "SELEC * FROM MY.TABNAME", PL/SQL allows more intelligent scripts to be run against the database as something like " IF DAY = 01 THEN ( INSERT (TOTALS) VALUES(%VAL) INTO TOTTAB ) ELSE (UPDATE TOTTAB SET TOTALS = TOTALS + %VAL")   

A:

Regarding to your question "which one to use when". Some Oracle gurus recommend:

First try to solve your problem with plain SQL
If you can't do it with sql, then try PL/SQL
Only use other languages like Java externally of your database if you can't do it internally.

But of course you can treat your database as a dump storage of data and do all the business logic externally in a separate layer.

