Friday, March 9, 2018

PL/SQL - SELECT statement using cursor

DECLARE
       CURSOR c_deptno IS SELECT first_name, salary, department_id
       FROM EMP;
BEGIN
     For x in c_deptno
    Loop
     dbms_output.put_line(x.first_name ||' '||x.salary||' '||x.department_id);
    End loop;
     close c_deptno;
End;

output:
        Steven 24000 90
        Neena 17000 90
        Lex 17000 90
        Alexander 9000 60

👋 Hi, I'm Suriya — QA Engineer with 4+ years of experience in manual, API & automation testing.

📬 Contact Me | LinkedIn | GitHub

📌 Follow for: Real-Time Test Cases, Bug Reports, Selenium Frameworks.

PL/SQL: SELECT Using Explicit Cursor to Fetch All Records

Note:
        An explicit cursor returns more than one row.

declare
       cursor v_cur is select employee_id,first_name,salary
       from emp;
       v_id emp.employee_id%type;
       v_name emp.first_name%type;
       v_sal emp.salary%type;
begin
      open v_cur;
      loop
      fetch v_cur into v_id,v_name,v_sal;
      exit when v_cur%notfound;
      dbms_output.put_line(v_id||' '||v_name||' '||v_sal);
      end loop;
      close v_cur;
end;

output:
100 Steven 24000
101 Neena 17000
102 Lex 17000
103 Alexander 9000
104 Bruce 6000
105 David 4800

👋 Hi, I'm Suriya — QA Engineer with 4+ years of experience in manual, API & automation testing.

📬 Contact Me | LinkedIn | GitHub

📌 Follow for: Real-Time Test Cases, Bug Reports, Selenium Frameworks.

PL/SQL Cursor to Return One Row with Multiple Columns: Example Guide

declare
       cursor s is select employee_id,first_name,salary
       from emp ;
       v_id emp.employee_id%type;
       v_name emp.first_name%type;
       v_sal emp.salary%type;
begin
      open s;
   
      fetch s into v_id,v_name,v_sal;
      dbms_output.put_line(v_id||' '||v_name||' '||v_sal);
   
end;

OUTPUT:
     100 Steven 24000

👋 Hi, I'm Suriya — QA Engineer with 4+ years of experience in manual, API & automation testing.

📬 Contact Me | LinkedIn | GitHub

📌 Follow for: Real-Time Test Cases, Bug Reports, Selenium Frameworks.

PL/SQL Anonymous Block to Return Multiple Columns: How-To Guide

declare
       v_id emp.employee_id%type:=&v_no;
       v_name emp.first_name%type;
       v_sal emp.salary%type;
begin
      select employee_id,first_name,salary
      into v_id,v_name,v_sal
      from emp
      where employee_id= v_id;
      dbms_output.put_line(v_id|| ' ' ||v_name||' '||v_sal);
end;

output :
 101 Neena 17000

👋 Hi, I'm Suriya — QA Engineer with 4+ years of experience in manual, API & automation testing.

📬 Contact Me | LinkedIn | GitHub

📌 Follow for: Real-Time Test Cases, Bug Reports, Selenium Frameworks.

PL/SQL Program to Accept Two Numbers and Print the Largest

declare

       x number;
       y number;
begin
      x :=&x;
      y :=&y;
      if( x > y)then
       dbms_output.put_line('x is largest than y');
       else
          dbms_output.put_line('y is largest than x');
   
      end if;
end;

👋 Hi, I'm Suriya — QA Engineer with 4+ years of experience in manual, API & automation testing.

📬 Contact Me | LinkedIn | GitHub

📌 Follow for: Real-Time Test Cases, Bug Reports, Selenium Frameworks.