You are on page 1of 4

> select * from v$version > Oracle version

> The size of a trigger cannot be more than 32K.


> Inside a trigger : Variables cannot be declared using the LONG or LONG RAW dat
atypes.
>Only committed triggers are fired. For example, if you create a trigger that sh
ould be fired after all CREATE events, then the trigger itself does not fire aft
er the creation, because the correct information about this trigger was not comm
itted at the time when the trigger on CREATE events was fired.
For example, if you execute the following SQL statement:
CREATE OR REPLACE TRIGGER my_trigger AFTER CREATE ON DATABASE
BEGIN null;
END;
Then, trigger my_trigger is not fired after the creation of my_trigger. Oracle D
atabase does not fire a trigger that is not committed.
>Triggers, in contrast, are fully compiled when the CREATE TRIGGER statement is
entered, and the pcode is stored in the data dictionary. Hence, firing the trigg
er no longer requires the opening of a shared cursor to run the trigger action.
Instead, the trigger is executed directly.
>The following data dictionary views reveal information about triggers:
USER_TRIGGERS
ALL_TRIGGERS
DBA_TRIGGERS
>SELECT dbtimezone FROM dual
SELECT sessiontimezone,dbtimezone,systimestamp,current_timestamp FROM dual
v$timezone_names
>A clustered table is a table that is part of a cluster.
A cluster is a group of tables that share the same data blocks because they shar
e
common columns and are often used together. Maximum number of tables allowed in
a cluster is 32.
>Maximum number of tables per database - Unlimited

>maximum number of columns in a table or view is 1000


>Maximum indexes per table - Unlimited
Maximum columns per index - 32 columns
Maximum columns per bitmapped index - 30 columns
>Maximum constraints per columns - Unlimited
> Subqueries
Maximum levels of subqueries in a SQL statement -
Unlimited in the FROM clause of the top-level query
-255 subqueries in the WHERE clause
>Rows - Maximum number per table - Unlimited
>Stored Packages - Maximum size-
PL/SQL and Developer/2000 may have limits on the size of stored procedures they
can call.
The limits typically range from 2000 to 3000 lines of code.
>select * from USER_OBJECT_SIZE where name='TBMS_CM_API_PKG'
>we never actually initialize nor declare I. In fact, the I in the loop is
a totally different variable. Even if you have an I variable declared, the loop
will still use its
own version. You can verify that by running this code:
DECLARE
I NUMBER(6);
BEGIN
I := 7;
DBMS_OUTPUT.PUT_LINE( BEFORE LOOP I: || I);
FOR I IN 1..5
LOOP
DBMS_OUTPUT.PUT_LINE( IN LOOP I: || I);
END LOOP;
DBMS_OUTPUT.PUT_LINE( AFTER LOOP I: || I);
END;
Which interestingly enough, prints out:
BEFORE LOOP I: 7
IN LOOP I: 1
IN LOOP I: 2
IN LOOP I: 3
IN LOOP I: 4
IN LOOP I: 5
AFTER LOOP I: 7
>Cursor Attributes
%NOTFOUND
%FOUND
%ISOPEN
%ROWCOUNT
> To Check oracle version& character set
SELECT VALUE FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER ='NLS_CHARACTERSET'
SELECT VALUE FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER ='NLS_RDBMS_VERSION'
>To see the system privileges of a user
select * from dba_sys_privs where grantee = USER
>v$parameter

>Duplication removal query


/*SELECT
**/
DELETE
FROM
LOG l
WHERE
ROWID NOT IN (SELECT ROWID FROM LOG l1 WHERE l.val=l1.val AND
l.description=l1.description AND
ROWNUM<2) AND
ROWID IN(SELECT ROWID FROM LOG l2 WHERE l.val=l2.val AND
l.description=l2.description)
>The precision specified for a number column in a CREATE/ALTER TABLE or CREATE C
LUSTER statement must be a digit between 1 and 38. If no precision is specified,
a default precision of 22 digits is used.
>alter session set skip_unusable_indexes = true;
alter index your_index unusable;
alter index your_index rebuild [online];

>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'

You might also like