Showing posts with label oracle - cursor. Show all posts
Showing posts with label oracle - cursor. Show all posts

Thursday, January 25, 2018

ORACLE - How make PL/SQL cursor with parameter(s)

function CreateInvoice( pNumber varchar2, pErrorMessage out varchar2 ) return number
is
  cursor c_sets( pLief_sch_nr varchar2 ) is
    select * from table
    where
    lief_sch_nr = pLief_sch_nr and
    c_px = 1   
    ;
  pc_sets   c_sets%rowtype;
begin
  ...
  open c_sets( pNumber );
    loop
      fetch c_sets into pc_sets;
      exit when c_sets%notfound;
      ...
    end loop;
  close c_sets;

Monday, December 11, 2017

ORACLE - How make cursor and how go through its rows

With Oracle cursor you can read table data by SQL.
is
  /* person`s list */

  cursor c_persons is
    select a.id, a.email
    from factory.an_users a
    where
    nvl( a.active, 'N' ) = 'A'
    ;

  pc_persons c_persons%rowtype;

  sEmail varchar2( 4000 );
begin
  ...
  sEmail := '';
  
  /* open cursor */ 
  open c_persons;
  loop

    /* read every rows of the cursor */
    fetch c_persons into pc_persons;
    exit when c_persons%notfound;

    /* -- action with row data.. */
    if pc_persons.email is not null then
      sEmail := sEmail || pc_persons.email || ';';
    end if;
    
  end loop;
  close c_persons;
  ...
end;