Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: SQL commands

Re: SQL commands

From: Rudi <nospam_at_127.0.0.1>
Date: Thu, 05 Aug 1999 10:41:37 +0100
Message-ID: <37A95C51.1F94@127.0.0.1>


Puneet Khanna wrote:
>
> I want to know the sql command by which i can select tables and views from
> tab, which contain the word "dba". I know the command by which i can get the
> rows in which the table/view name starts with "dba". The problem is if the
> word is in between like ORA_DBA_ABC.
>
> Also, what is a decode function? where is it used?
> I do not find oracle doc. very helpful, pls. tell me a good book for PL/SQL
> and SQL.

Use this:

SELECT mycolumn
FROM mytable
WHERE mycolumn LIKE '%DBA%'

The DECODE function works a bit like the LOOKUP functions in Excel. It lookups a column or expression, and depending on the value it finds it returns a "translated" or "decoded" value. Basically you specify the field or expression you want to decode, pairs of matching values and optionally a default value if no match is found...

For instance If you had a column containing the following values 1, 2, 3, 4 and you wanted to translate the numbers into 'first', 'second', etc.
you could use it like this:

SELECT DECODE(mycolumn,

              1, 'First',
              2, 'Second',
              3, 'Third',
             'any other value)

FROM mytable

Rudi Received on Thu Aug 05 1999 - 04:41:37 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US