Combine for loop and if statement to check the value in cursor : Explicit Cursor « Cursor « Oracle PL / SQL






Combine for loop and if statement to check the value in cursor

  

SQL> CREATE TABLE products(
  2    name            VARCHAR2(50),
  3    price         NUMBER(8,2),
  4    min_price          NUMBER(8,2)
  5  );

Table created.

SQL>
SQL>
SQL> create or replace procedure print_products as
  2      cursor dataCursor is select name, price from products;
  3    begin
  4       for i in dataCursor LOOP
  5           if i.price > 50 then
  6              dbms_output.put_line(i.name ||' Price: '|| i.price);
  7           else
  8              dbms_output.put_line(i.name || ' Product under 50');
  9           end if;
 10       END LOOP;
 11   end;
 12  /

Procedure created.

SQL>
SQL> execute print_products

PL/SQL procedure successfully completed.

SQL>
SQL> drop table products;

Table dropped.

SQL>

   
    
  








Related examples in the same category

1.Explicit Cursor Demo
2.Implicit and Explicit Cursors
3.an explicit cursor that selects data
4.An explicit cursor fetch loop.
5.Use cursor to store the row count
6.Column value indexed cursor
7.Cursor performance
8.Delete from table where current of cursor
9.If statement and single piece value in cursor
10.Use explicit cursor to fetch and store value to number variable
11.Write an explicit cursor in a FOR loop and use the data