oracle pl sql error oracle pl sql error oracle pl sql error
 

Oracle Functions


In Oracle, you can create your own functions.

The syntax for create function is:

CREATE [OR REPLACE] FUNCTION function_name     [ (parameter [,parameter]) ]     RETURN return_datatype IS | AS     [declaration_section] BEGIN     executable_section [EXCEPTION     exception_section] END [function_name];

When you create a Oracle procedure or function, you may define parameters. There are three types of parameters that can be declared:

IN - The parameter can be referenced by the procedure or function. The value of the parameter can not be overwritten by the procedure or function. OUT - The parameter can not be referenced by the procedure or function, but the value of the parameter can be overwritten by the procedure or function. IN OUT - The parameter can be referenced by the procedure or function and the value of the parameter can be overwritten by the procedure or function.

The following is a simple example of a oralce function:

CREATE OR REPLACE Function FindCourse    ( name_in IN varchar2 )    RETURN number IS     cnumber number;

    cursor c1 is     select course_number       from courses_tbl       where course_name = name_in; BEGIN

open c1; fetch c1 into cnumber; if c1%notfound then      cnumber := 9999; end if; close c1;

RETURN cnumber;

EXCEPTION WHEN OTHERS THEN       raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM); END;

This function is called FindCourse. It has one parameter called name_in and it returns a number. The function will return the course number if it finds a match based on course name. Otherwise, it returns a 99999.

You could then reference your new function in an Oracle SQL statement as follows:

select course_name, FindCourse(course_name) as course_id from courses where subject = 'Mathematics';

 

 
 

Create a Oracle functions Based Index

In oracle pl sql error, you are not restricted to creating indexes on only columns. You can create function-based indexes.

The syntax for creating a function-based index is:

CREATE [UNIQUE] INDEX index_name   ON table_name (function1, function2, . function_n)   [ COMPUTE STATISTICS ];

For example:

CREATE INDEX supplier_idx    ON supplier (UPPER(supplier_name));

In this example, we've created an index based on the uppercase evaluation of the supplier_name field.

However, to be sure that the Oracle optimizer uses this index when executing your SQL statements, be sure that UPPER(supplier_name) does not evaluate to a NULL value. To ensure this, add UPPER(supplier_name) IS NOT NULL to your WHERE clause as follows:

SELECT supplier_id, supplier_name, UPPER(supplier_name) FROM supplier WHERE UPPER(supplier_name) IS NOT NULL ORDER BY UPPER(supplier_name);

Rename an Oracle Index

The syntax for renaming an index is:

ALTER INDEX index_name   RENAME TO new_index_name;

For example:

ALTER INDEX supplier_idx   RENAME TO supplier_index_name;

In this example, we're renaming the index called supplier_idx to supplier_index_name.

Collect Statistics on an Index

If you forgot to collect statistics on the index when you first created it or you want to update the statistics, you can always use the ALTER INDEX command to collect statistics at a later date.

The syntax for collecting statistics on an index is:

ALTER INDEX index_name   REBUILD COMPUTE STATISTICS;

For example:

ALTER INDEX supplier_idx   REBUILD COMPUTE STATISTICS;

In this example, we're collecting statistics for the index called supplier_idx.

Drop an Index

The syntax for dropping an index is:

DROP INDEX index_name;

For example:

DROP INDEX supplier_idx;

In this example, we're dropping an index called supplier_idx.

 
 
Oracle news Oracle guide
 
     
  29-11-2006 Guida Oracle 10g
     
  30-02-2007 Oracle Server
     
  29-02-2007 Oracle Errors
Functions Oracle Functions
Delete Delete
Between Between
Check Check
Count Count
Datatypes Datatypes
Delete Oracle Delete Statement
Distinct Distinct
Exists Exists
Functions Oracle10g
Grant revoke Grant Revoke
Group by Oracle Group by
Having Having
Oracle Function in Oracle Function in
Indexes Indexes
Insert Insert
Intersect Intersect
Isnull Is null
Joins Joins
Substr Substr
instr Oracle instr
blob Oracle blob
roles Oracle roles
Substr Substr
like Oracle like
Substr Oracle minus
Substr Oracle to_number
union Oracle union
query Oracle query
Substr Oracle unique
Substr Oracle union all
Substr Oracle alter table
 
Oracle Functions PLSQL  l  Exceptions  l  Oracle Errors  l  Oracle Collaborations Suite  l  Products  l  Contact
Oracle errors ora