PL/SQL Working with Cursors


SELECT-INTO

Simple Select
declare
  l_last_name employees.last_name%type;
begin
  select last_name
    into l_last_name
    from employees
    where employee_id=138;
 
    dbms_output.put_line(l_last_name);
end;

Join

declare
  l_last_name employees.last_name%type;
  l_department_name departments.department_name%type;
begin
  select last_name, department_name
  into l_last_name, l_department_name
  from employees e, departments d
  where e.department_id=d.department_id
  and e.employee_id=138;

  dbms_output.put_line(
        l_last_name||
        ' is working in '||
        l_department_name ||
        ' department.');
end;

Cursor FOR Loop


declare
  cursor test_cur
  is
    select * from employees
    where department_id=50;
begin
  for c1
  in test_cur
  loop
    dbms_output.put_line(
      c1.first_name||
      ' '||
      c1.last_name
    );
  end loop;
end;


Comments

Popular posts from this blog

Solution for "Can not obtain Oracle client information from registry"

Solution for the fault: "System.Diagnostics.Process.Start is not working on IIS, but working on ASP.NET Development Server"

Getting Umbraco Content - IPublishedContent vs IContent vs Node vs Document