Click here to Skip to main content
15,891,136 members
Articles / Oracle

Some of the Many Quirks of Oracle

Rate me:
Please Sign up or sign in to vote.
3.75/5 (3 votes)
26 Sep 2014CPOL 10.4K   1   3
Some of the many quirks of Oracle

Oracle is a huge database system, one that I have used many times over my career. It has its good points. It has also been likened to a beast on more than one occasion by the various multitudes.

These quirks are in no certain or consistent order (just like the results from a SELECT statement in Oracle).

Booleans in PL/SQL

PL/SQL allows you to use a boolean type. Oracle's query language implementation does not. You can't do this:

SQL
FUNCTION IllustrateBooleanQuirk()
                RETURN BOOLEAN
IS
    v_result BOOLEAN := FALSE; 
BEGIN
    SELECT ( MOD(QuirkSequence.NEXTVAL, 2) = 1 )
    INTO   v_result
    FROM   DUAL;

    RETURN V_RESULT;
END;

But you can get around it by performing a comparison in the RETURN for this function:

SQL
FUNCTION IllustrateBooleanQuirk()
                RETURN BOOLEAN
IS
  v_result VARCHAR2 (5) := 'FALSE';
BEGIN
    SELECT CASE
             WHEN MOD(QuirkSequence.NEXTVAL, 2) = 1 THEN 'FALSE'
             ELSE 'TRUE'
           END
    INTO   v_result
    FROM   DUAL;

    RETURN ( V_RESULT = 'TRUE' );
END;

Applying "parameters" to a query

Sometimes, you just want to define a parameter or constant for a query without having to use PL/SQL. In my case, it is because I want the results of the query to be displayed in dbForge in a results grid. You can use the DEFINE command to set a replacement value. Oracle will take all of the DEFINEs executed prior to your DML/DDL, and replace each one as if you had typed in the quoted value in your query.

SQL
DEFINE SomeParameterish = "'12345'";

SELECT &SomeParameterish AS FakeColumn 
FROM   DUAL;

would execute as:

SQL
SELECT '12345' AS FakeColumn 
FROM   DUAL;

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
Long time software engineer who rambles occasionally about coding, best practices, and other random things.

Comments and Discussions

 
GeneralMy vote of 3 Pin
Mass Nerder25-Sep-14 3:03
Mass Nerder25-Sep-14 3:03 
GeneralRe: My vote of 3 Pin
Adam Zuckerman25-Sep-14 5:54
Adam Zuckerman25-Sep-14 5:54 
GeneralRe: My vote of 3 Pin
KarstenK25-Sep-14 6:42
mveKarstenK25-Sep-14 6:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.