Thursday, 6 March 2014

PL SQL REF CURSOR


  • A REF CURSOR is basically a data type.  A variable created based on such a data type is generally called a cursor variable.
  • A cursor variable can be associated with different queries at run-time.
  • The primary advantage of using cursor variables is their capability to pass result sets between sub programs (like stored procedures, functions, packages etc.
Ref Cursors are categorized as of two types:
  • Strongly Typed :The REF CURSOR type is restricted to an individual return type using the RETURN clause, reducing the chance of run-time errors, but restricting the flexibility.
  • Weakly Typed: The RETURN clause is omitted allowing the type to reference any return type.  This gives greater flexibility, but it increases the likelihood of runtime errors because column mismatches are not picked up at compile time.
Example Strongly typed REF CURSOR:

DECLARE
  TYPE t_ref_cursor IS REF CURSOR
RETURN cursor_variable_test%ROWTYPE;
  c_cursor  t_ref_cursor;
  l_row     cursor_variable_test%ROWTYPE;
BEGIN
  DBMS_OUTPUT.put_line('Strongly typed REF CURSOR');
  OPEN c_cursor FOR
    SELECT
*  FROM   cursor_variable_test;
  LOOP
    FETCH
c_cursor  INTO  l_row;
    EXIT WHEN c_cursor%NOTFOUND;
    DBMS_OUTPUT.put_line(l_row.id || ' : ' || l_row.description);
  END LOOP; 
  CLOSE c_cursor;
END;
/

Example Weakly typed REF CURSOR:
DECLARE
  TYPE t_ref_cursor IS REF CURSOR;
  c_cursor  t_ref_cursor;
  l_row     cursor_variable_test%ROWTYPE;
BEGIN
  DBMS_OUTPUT.put_line('Weakly typed REF CURSOR');
  OPEN c_cursor FOR
    SELECT
*   FROM   cursor_variable_test;
  LOOP
    FETCH
c_cursor   INTO  l_row;
    EXIT WHEN c_cursor%NOTFOUND; 
    DBMS_OUTPUT.put_line(l_row.id || ' : ' || l_row.description);
  END LOOP;
  CLOSE c_cursor;
END;
/

Example REF CURSOR with different queries:
DECLARE
TYPE empcurtyp IS REF CURSOR RETURN employees%ROWTYPE;
emp empcurtyp;
BEGIN
-- First find 10 arbitrary employees.
 OPEN emp FOR SELECT * FROM employees WHERE ROWNUM < 11; process_emp_cv(emp); // it is already created.
CLOSE emp;
-- find employees matching a condition.
OPEN emp FOR SELECT * FROM employees WHERE last_name LIKE 'R%'; process_emp_cv(emp);
CLOSE emp;
END;
/ 



Also Check: PL SQL Cursors

Happy Coding :)

PL SQL CURSOR

  • A cursor is a temporary work area created in the system memory when a SQL statement is executed. 
  • This temporary work area is used to store the data retrieved from the database, and manipulate this data. 
  • A cursor can hold more than one row, but can process only one row at a time.
  • The set of rows the cursor holds is called the active set.
There are two types of cursors are there in Pl/sql known as Implicit Cursor and Explicit Cursor.

Implicit Cursor:
  • Declared for every PLSQL DML or SELECT statement and maintained by Oracle server internally.
  • We can use implicit cursor attributes to verify of the last executed statement 
Implicit Cursor Attributes:
  • SQL%ROWCOUNT : Returns number of rows effected by most recent sql statement
  • SQL%FOUND : Returns TRUE if the most recent sql statement effects one or more rows
  • SQL%NOTFOUND : Returns TRUE if the most recent sql statement doesn't effects any rows
  • SQL%ISOPEN : Always returns FALSE becose oracle close the cursor immediately after they executed.
      Explicit Cursor:
  •      Declared for queries that return more than one row and maintained by the programmer
  •      We Can evaluate the cursor status using explicit cursor attributes.
    Explicit Cursor Attributes:
  •     cur_var%ROWCOUNT :  Returns number of rows fetched so far
  •     cur_var%FOUND : Returns TRUE if the recent fetch contains a row
  •     cur_var%NOTFOUND : Returns TRUE if the recent fetch doesn't have a row
  •     cur_var%ISOPEN : Returns TRUE if the cursor is open
Below are the steps to use a cursor.
-- Declare a cursor 
-- Open the Cursor
-- Fetch the records from the cursor
-- Close the Cursor






At the time of declaration of a cursor we need to give the cursor name and the query which is fetch the records from the table.
When we open the cursor the cursor pointer points to the first record of the Active result set.

When we fetch one record from the cursor pointer points to the next record on the cursor.

When we close the cursor it releases the memory area.



For Example:
SET SERVEROUTPUT ON
DECLARE
v_name  employee.empname%TYPE;
v_sal  employee.salary%TYPE;
CURSOR emp_cur IS
SELECT empname,salary from employee;
BEGIN
IF  NOT emp_cur %ISOPEN THEN
    OPEN emp_cur ;
END IF;

LOOP
    FETCH emp_cur INTO v_name , v_sal;
    Dbms_output.put_line(‘Line number :’|| emp_cur%ROWCOUNT||
    ‘fetched. Name : ’|| v_name ||’  salary : ’|| v_sal);
EXIT WHEN emp_cur%NOTFOUND;
END LOOP;
CLOSE emp_cur ;
END;

Cursor For Loop:

After declaring a cursor, using Cursor For Loop we can directly do  Open, Fetch and close the cursor using a cursor for loop.
For example

FOR  rec IN emp_cur LOOP
Dbms_output.put_line(‘Line number :’|| emp_cur%ROWCOUNT||
‘fetched. Name : ’||rec.empname ||’  salary : ’|| rec.salary);
END LOOP;

Cursor For Loop Using SubQuery:

Using Cursor for loop with subquery we do all the operations i.e. declare,open, fetch and close a cursor directly.
For Example,

FOR emp_rec IN (SELECT empname, salary from employee)
LOOP
……………. –pl/sql statements

END LOOP;






Also check : PL SQL REF Cursor

Happy Coding :)


Create Quataion,Requisition and Purchase Orders with mannual Alphanumeric values in EBS R12

By default the requisition number, Purchase Order number and quatation number is generated from a numeric sequence value in Oracle E-Business suite R12.

But in the setups user has given an option to override it and create the PO, Requisition and Quatations with manual numbers or alphanumeric values. Here is the setup mentioned below to do the same.


  • Goto Purchasing, Vision Operations (USA) > Setups > Organizations > Purchasing options.


  • on the Document numbering section we can change the Document, Entry, Type according to our requirement. The possible values are as mentioned below snapshot.














Happy Coding :)

Monday, 3 March 2014

Using API Load Currency In Oracle EBS R12

Below is the sample procedure to create Currency in Oracle EBS R12 using .

PROCEDURE currency_create(p_currency_code IN VARCHAR2,
                       p_teritory_code IN VARCHAR2,
                       p_precision IN NUMBER,
                       p_extended_precision IN NUMBER,
                       p_symbol IN VARCHAR2,
                       p_currency_name IN VARCHAR2
                       )
 BEGIN
     APPS.MO_GLOBAL.INIT ('PO');
     APPS.MO_GLOBAL.SET_POLICY_CONTEXT ('S', 204);
     APPS.FND_GLOBAL.APPS_INITIALIZE ( USER_ID => 1318, RESP_ID => 50578, RESP_APPL_ID => 201 );

apps.fnd_currencies_pkg.LOAD_ROW ( p_currency_code,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  'Y',
                                  'Y',
                                  p_teritory_code,
                                  p_precision,
                                  p_extended_precision,
                                  p_symbol,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  'Y',
                                  NULL,
                                  p_currency_name,
                                  NULL,
                                  'apps') ;
 commit;
 END currency_create;


Happy Coding. :)

Test A BPEL Process Initiated By DBAdapter Polling

When a BPEL process initiated by the polling inbound operation of a DBAdapter, the test button is disabled on the EM i.e. it is not allow you test it in EM.

For Example,

Consider the below BPEL process which is iniated by a DB Adapter which polls to the Employee table.










After deploy the above BPEL process in the EM the test button is disabled.











Here the reason is this BPEL process will automatically trigger depending upon the records modified or inserted on the corresponding polling table.

We can test this BPEL process explicitly from the Weblogic Enterprise Manager by exposing the BPEL with SOAP binding. Please follow the below steps to do the same.

























Now redeploy and go to the EM test it.

















Also Check: DB Adapter polling multiple records form Database

Happy Coding.