Friday, 14th October 2011
Follow WikiJava on twitter now. @Wikijava

RecordDemo.sql

From WikiJava

Jump to: navigation, search


This tutorial talks about PL/SQL Record type.

Contents

the article

A record is a group of related data items stored in fields, each with its own name and datatype. You can think of a record as a variable that can hold a table row, or some columns from a table row. The fields correspond to table columns.

This simple example shows how to create a record and use it to manipulate data.

RecordDemo.sql

-- This is were you declare variables that will be needed.
 
DECLARE
 
-- declare a record type with two fields to select the rows you wish 
 
-- to retrive the %TYPE attribute declare a variable which will
 
-- use the default data type of the column in the table 
 
 TYPE emp_rec_type IS RECORD (empno emp.empno%TYPE,ename emp.ename%TYPE);
 
 
-- declare a record that will hold the rows retrieved from the table.   
   emp_rec emp_rec_type;
 
-- start the loop with the keyword BEGIN
   BEGIN
 
   LOOP
 
-- select the rows you want to manipulate
   SELECT empno,ename
 
-- The rows selected will be put into the emp_rec record
   INTO emp_rec
 
-- specify the table where the data is being retrived from
   FROM emp;
 
-- merge the two fields and print out the results 
   DBMS_OUTPUT.PUT_LINE(emp_rec.empno

Comments from the users

To be notified via mail on the updates of this discussion you can login and click on watch at the top of the page

Interesting

PL/SQL is a very important skill to gain. This article is very important. I'd like to see some more descriptions about what it does and how.

--DonGiulio 10:55, 22 October 2008 (PDT)


Eliza

That's not even 10 mniutes well spent!

--Eliza 22:49, 17 August 2011 (PDT)


Comments on wikijava are disabled now, cause excessive spam.