Sie sind auf Seite 1von 4

chmod

chgrp
chown
oracle all_user , dba_user,
How to find indexes which are candidate for rebuild?
Find out indexes having height(blevel+1) > 4 i.e. Indexes having BLEVEL > 3
How:
SQL> select owner,index_name,table_name,blevel from dba_indexes where BLEVEL>3
SQL> analyze index TEST_INDX validate structure; -- First analyze the suspect in
dex
Index analyzed.
SQL> SELECT name,height,lf_rows,lf_blks,del_lf_rows FROM INDEX_STATS;
NAME HEIGHT LF_ROWS LF_BLKS DEL_LF_ROWS
------------ ---------- ---------- ----------- -------------
TEST_INDX 8 938752 29575 73342
You can see height of the index is 8 and also high number of DEL_LF_ROWS;
Now you rebuild the indexes
SQL> alter index TEST_INDX rebuild;
Index altered.
SQL> SELECT name,height,lf_rows,lf_blks,del_lf_rows,distinct_keys,used_space FRO
M INDEX_STATS;
NAME HEIGHT LF_ROWS LF_BLKS DEL_LF_ROWS
------------------------------ ---------- ---------- ---------- -----------
TEST_INDX 4 865410 15434 0

This clearly indicates rebuild helped my query performance. The height of index
is reduced to 4 and DEL_LF_ROWS is 0
--------------------------------------------------------------------------------
---------------------------------------------------------
--------------------------------------------------------------------------------
-----------------------------------------------------------
1)Can you use sysdate in check constraints? If no, why?Let me explain with one s
imple example?
No, you can't use sysdate in check constraints.
Why?
All rows in a table for an enabled constraint must return true for its expressio
n.
But sysdate is non-deterministic. You can get a different result every time you
call it. So the outcome (true/false) can (will) change over time. So Oracle can'
t guarantee that the expression is always true for every row.
--------------------------------------------------------------------------------
-----------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------
PL/SQL Trigger Execution Hierarchy
The following hierarchy is followed when a trigger is fired.
1) BEFORE statement trigger fires first.
2) Next BEFORE row level trigger fires, once for each row affected.
3) Then AFTER row level trigger fires once for each affected row. This events wi
ll alternates between BEFORE and AFTER row level triggers.
4) Finally the AFTER statement level trigger fires.
--------------------------------------------------------------------------------
-----------------------------------------------------------------
--------------------------------------------------------------------------------
-----------------------------------------------------------------
When we can declare a column as Unique and Not Null both at the same time. What
is the use pf Primary Key then?
Hi ,
The concept of adding an unique key and not null constraint to a column as well
as adding as unique index to it , you will assume to get the benefits of addin
g an
primary key to that column.
But use it for the purpose of referential integrity will not allow to do so.
That's what PK is so useful.
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Can we use IN , OUT and INOUT Parameter in Function.
Yes , a function can have all three modes for parameters but underlying fact is
that function should return only one value.
Function can be used in select statement only when return clause is used , i.e r
eturn one value.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
What are SQLCODE and SQLERRM and why are they important for PL/SQL developers?
- SQLCODE: It returns the error number for the last encountered error.
- SQLERRM: It returns the actual error message of the last encountered error.
- When a SQL statement raises an exception, Oracle captures the error codes by u
sing the SQLCODE and SQLERRM globally-defined variables.
- SQLCODE and SQLERRM can track exceptions that are handled by the OTHERS clause
of the exception handler.
- SQLCODE returns the current error code from the error stack and the error mess
age from the current error.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
---
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----
Difference between TO_Date and To_Char
to_char function is used to convert the given data into character....
eg:to_char(sysdate,'month') which returns month alone...
to_date is used to convert the given data into date data formate data type....
eg: to_date('070903', 'MMDDYY') would return a date value
of July 9, 2003.

----------------
A lot of people have confusion about the usage of to_char and to_date functions.
When to use to_char and when to use to_date. Here I am going to tell you how to
do that. I will be discussing to_char function with respect to date only and no
t with numbers.
Syntax
to_char(value , format_mask)
to_date(string , format_mask)
So when you want to convert a date to a string use to_char function. Always reme
mber that INPUT to to_char function is always a date (excluding numbers here). A
format mask over here decides how OUTPUT of to_char function will look. Lets co
nsider this with an example.

sql > Select to_char(sysdate,'DD-MM-YYYY') from dual;


Output : 01-01-2001
INPUT -> sysdate ( a date)
OUTPUT -> 01-01-2001 ( DD-MM-YYYY the format mask)
And when you want to convert a string to a date use to_date function. Always rem
ember that OUTPUT of to_date function is always a date. A format mask over here
decides what will the format of INPUT string. Lets have an example.
sql > select to_date( '01-01-2001','DD-MM-YYYY') from dual;
Output : 01-JAN-01
INPUT -> 01-01-2001 ( format_mask is 'DD-MM-YYYY')
OUTPUT -> 01-JAN-01 ( a date, the format here is the default NLS setting for you
r date)
Just remember the input and output of these functions and you will never make a
mistake.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----
One can call DDL statements like CREATE, DROP, TRUNCATE,
etc. from PL/SQL by using the "EXECUTE IMMEDATE" statement.
Users running Oracle versions below 8i can look at the
DBMS_SQL package .
begin
EXECUTE IMMEDIATE 'CREATE TABLE X(A DATE)';
end;
NOTE: The DDL statement in quotes should not be terminated
with a semicolon.
-------------------------------------------------------------------------------
----------------------------------------------------------------------------

Das könnte Ihnen auch gefallen