Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: SQL commands
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)
Rudi Received on Thu Aug 05 1999 - 04:41:37 CDT