Professional Documents
Culture Documents
>exec dbms_stats.gather_schema_stats('NCC_SITE_API');
>In Oracle/PLSQL, the coalesce function returns the first non-null expression in
the list. If all expressions evaluate to null, then the coalesce function will
return null.
The syntax for the coalesce function is:
coalesce( expr1, expr2, ... expr_n )
Applies To:
Oracle 9i, Oracle 10g, Oracle 11g
For example:
You could use the coalesce function in an SQL statement as follows:
SELECT coalesce( address1, address2, address3 ) result
FROM suppliers;
The above coalesce statement is equivalent to the following IF-THEN-ELSE stateme
nt:
IF address1 is not null THEN
result := address1;
ELSIF address2 is not null THEN
result := address2;
ELSIF address3 is not null THEN
result := address3;
ELSE
result := null;
END IF;
The coalesce function will compare each value, one by one
>The SQLCODE function returns the error number associated with the most recently
raised error exception. This function should only be used within the Exception
Handling section of your code.You cannot use SQLCODE directly in a SQL statement
. Assign the value of SQLCODE to a local variable first.
>instr('some string','search string')
instr('some string','search string',position)
instr('some string','search string',position,occurence)
Instead of instr, instrb (bytes), instrc (unicode), instr2 (UCS2 code points) an
d instr4 (UCS4 code points)) are also possible. position and occurence default t
o 1, if not explicitly indicated. The instr family returns the start position of
the occurenceth search string within some string after the character at positio
n position. If it doesn't find search string, it returns 0. position can be nega
tive in which case it counts from the end of search string.
>Example For EXTRACT
-------------------
create table some_things of xmltype;
Three xml documents are inserted into the table.
insert into some_things values (xmltype('
<things>
<numbers><item>1</item><item>59</item></numbers>
<animals><item>bird</item><item>cat</item><item>dog</item></animals>
</things>
'));
insert into some_things values (xmltype('
<things>
<countries><item>Canada</item><item>Egypt</item><item>Italy</item></countrie
s>
<numbers><item>55</item><item>101</item></numbers>
</things>
'));
insert into some_things values (xmltype('
<things>
<cities><item>New York</item><item>Tokyo</item><item>Zurich</item></cities>
<animals><item>elephant</item><item>snake</item></animals>
</things>
'));
Selecting the 2nd animal in each document:
select extract(object_value,'/things/animals/item[position()=2]') "2nd Animal" f
rom some_things;
2nd Animal
------------------------------------------------------------
<item>cat</item>
<item>snake</item>
The 2nd inserted document doesn't have an animal, so null is returned instead.
>To see the currently running statements
SELECT s.SID, s.status, s.process, s.osuser, a.sql_text, p.program
FROM v$session s, v$sqlarea a, v$process p
WHERE s.sql_hash_value = a.hash_value
AND s.sql_address = a.address
AND s.paddr = p.addr
AND s.status = 'ACTIVE'
SELECT s.SID, s.status, s.process, s.osuser, a.sql_text, p.program
FROM v$session s, v$sqlarea a, v$process p
WHERE s.PREV_HASH_VALUE = a.hash_value
AND s.PREV_SQL_ADDR = a.address
AND s.paddr = p.addr
AND s.status = 'ACTIVE'