<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Techno Oracle &#187; Records in Oracle</title>
	<atom:link href="http://www.technooracle.com/oracle-tutorials/category/oracle-plsql/records-in-oracle/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.technooracle.com</link>
	<description>Oracle information centre</description>
	<lastBuildDate>Tue, 17 Apr 2012 12:07:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Using Records With Cursor</title>
		<link>http://www.technooracle.com/oracle-tutorials/using-records-with-cursor/</link>
		<comments>http://www.technooracle.com/oracle-tutorials/using-records-with-cursor/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 06:53:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Oracle PL/SQL]]></category>
		<category><![CDATA[Records in Oracle]]></category>
		<category><![CDATA[Declaring a Record to Match a Cursor]]></category>
		<category><![CDATA[Using Records With Cursor]]></category>

		<guid isPermaLink="false">http://www.technooracle.com/?p=299</guid>
		<description><![CDATA[Just as you can base a record on a table, you can also base a record definition on a cursor.Records that are based on an Oracle cursor draw their structure from the SELECT statement used for the cursor. This type of record has the same number of columns, with the same names and datatypes, as [...]]]></description>
			<content:encoded><![CDATA[<p>Just as you can base a record on a table, you can also base a record definition on a cursor.Records that are based on an Oracle cursor draw their structure from the <strong>SELECT</strong> statement used for the cursor. This type of record has the same number of columns, with the same names and datatypes, as those in the cursor. The <strong>%ROWTYPE</strong> keyword is used to declare the record that is based on a cursor.</p>
<p>Following Example shows a cursor named <strong>all_depts</strong>, and a record named dept that is based on that cursor.</p>
<h3><span style="color: #000080;">Declaring a Record to Match a Cursor</span></h3>
<p>1: DECLARE<br />
2: CURSOR all_depts is<br />
3: SELECT dept_id, dept_name<br />
4: FROM department<br />
5: ORDER BY dept_name;<br />
6:<br />
7: dept all_depts%ROWTYPE;<br />
8: BEGIN<br />
9: OPEN all_depts;<br />
10:<br />
11: LOOP<br />
12: EXIT WHEN all_depts%NOTFOUND;<br />
13: FETCH all_depts INTO dept;<br />
14: DBMS_OUTPUT.PUT_LINE(dept.dept_name);<br />
15: END LOOP;<br />
16:<br />
17: CLOSE all_depts;<br />
18: END;<br />
19: /</p>
<p>The cursor all_depts is declared in lines 2–5. In line 7, a record variable named<br />
dept is declared based on the definition of the cursor. Because the variable dept<br />
matches the cursor exactly, the FETCH statement in line 13 can fetch the results of the SELECT statement directly into the record. If at some point in the future you need to add columns to the select list, that change will automatically ripple through to the record definition,and the FETCH statement will continue to operate.</p>
<p><span style="color: #000080;"><br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.technooracle.com/oracle-tutorials/using-records-with-cursor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Record with SELECT Statements</title>
		<link>http://www.technooracle.com/oracle-tutorials/using-record-with-select-statements/</link>
		<comments>http://www.technooracle.com/oracle-tutorials/using-record-with-select-statements/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 13:47:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Oracle PL/SQL]]></category>
		<category><![CDATA[Records in Oracle]]></category>
		<category><![CDATA[Records With SELECT tatements]]></category>
		<category><![CDATA[Selecting a Specific Fields into a Record]]></category>
		<category><![CDATA[Selecting Directly into a Record]]></category>
		<category><![CDATA[Using Record with SELECT Statements]]></category>
		<category><![CDATA[using Records with SELECT statements]]></category>

		<guid isPermaLink="false">http://www.technooracle.com/?p=297</guid>
		<description><![CDATA[If you have a record where all the fields in the record correspond exactly to the fields being returned from a SELECT statement, you can retrieve the values directly into that record. Here’s an example: DECLARE dept department%ROWTYPE; BEGIN SELECT * INTO dept FROM department WHERE dept_id = 502; &#8230; END; / You don’t have [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a record where all the fields in the record correspond exactly to the fields being returned from a SELECT statement, you can retrieve the values directly into that record.</p>
<p>Here’s an example:</p>
<p>DECLARE<br />
dept department%ROWTYPE;<br />
BEGIN<br />
SELECT * INTO dept<br />
FROM department<br />
WHERE dept_id = 502;<br />
&#8230;<br />
END;<br />
/<br />
You don’t have to use %ROWTYPE when you do this, and you don’t have to use SELECT * either. The Following Example  shows the dept record being declared without the use of %ROWTYPE,<br />
<span id="more-297"></span><br />
Example</p>
<p>selects for department 452. If you don’t have that department,replace 452 with a valid number for your database.</p>
<h3><span style="color: #000080;">Selecting Directly into a Record</span></h3>
<p>1: DECLARE<br />
2: TYPE dept_type IS RECORD<br />
3: (<br />
4: dept_id department.dept_id%type,<br />
5: dept_name department.dept_name%type,<br />
6: no_of_emps department.no_of_emps%type<br />
7: );<br />
8:<br />
9: dept dept_type;<br />
10: BEGIN<br />
11: SELECT * INTO dept<br />
12: FROM department<br />
13: WHERE dept_id = 452;<br />
14: END;<br />
15: /</p>
<p>A record type named dept_type is defined in lines 2–7. The declaration in line 9<br />
declares a variable named dept to be of type dept_type. Because the fields in the<br />
dept_type record match exactly the fields in the Department table, the SELECT statement in lines 11–13 will work.</p>
<p>The Following example shows a SELECT statement other than SELECT *.<span style="color: #000080;"> </span></p>
<h3><span style="color: #000080;"> Selecting a Specific List of Fields into a Record</span></h3>
<p>1: DECLARE<br />
2: TYPE dept_type IS RECORD<br />
3: (<br />
4: dept_id department.dept_id%type,<br />
5: dept_name department.dept_name%type,<br />
6: no_of_emps department.no_of_emps%type<br />
7: );<br />
8:<br />
9: dept dept_type;<br />
10: BEGIN<br />
11: SELECT dept_id, dept_name, no_of_emps INTO dept<br />
12: FROM department<br />
13: WHERE dept_id = 452;<br />
14: END;<br />
15: /<br />
The three fields in the Department table are enumerated in the SELECT list.<br />
Because the number of fields (and their datatypes) corresponds with the definition of the dept_type record, you are able to retrieve the data directly into a variable of  <strong>type dept_type.</strong></p>
<p>The key thing to keep in mind when selecting data directly into a record is that the columns and datatypes represented in the SELECT list must correspond exactly to the fields and datatypes in the record definition. The column names and field names do not need to match, as Oracle assigns column values to fields in a record based on position,but the datatypes must match.</p>
<p>If you are using SELECT * to retrieve values from a table,you are safest using %ROWTYPE when declaring the record.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.technooracle.com/oracle-tutorials/using-record-with-select-statements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Records on Tables in Oracle</title>
		<link>http://www.technooracle.com/oracle-tutorials/using-records-on-tables-in-oracle/</link>
		<comments>http://www.technooracle.com/oracle-tutorials/using-records-on-tables-in-oracle/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 13:30:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Oracle PL/SQL]]></category>
		<category><![CDATA[Records in Oracle]]></category>
		<category><![CDATA[Using Records on tables]]></category>
		<category><![CDATA[Using Records on Tables in Oracle]]></category>

		<guid isPermaLink="false">http://www.technooracle.com/?p=295</guid>
		<description><![CDATA[If a record type variable is based on a table, it means that the fields in the record have the exact same name and data type as the columns in the specified table. You use the %ROWTYPE attribute to declare a record based on a table. To declare a record variable that exactly matches the [...]]]></description>
			<content:encoded><![CDATA[<p>If a record type variable is based on a table, it means that the fields in the record have the exact same name and data type as the columns in the specified table. You use the <strong>%ROWTYPE</strong> attribute to declare a record based on a table.<br />
To declare a record variable that exactly matches the definition of a table—that is, that contains one field for each column in the table—use the following syntax for the record<br />
type:</p>
<p><strong>table_name%ROWTYPE;</strong></p>
<p>where table_name is the name of the table. %ROWTYPE is a keyword that tells Oracle that the record should have one field for each column in the table, and that the datatypes of the fields should exactly match the datatypes of the columns.</p>
<p><span id="more-295"></span></p>
<p>The following example declares the variable dept so that it matches the definition of the Department table:</p>
<p><strong>DECLARE<br />
dept department%ROWTYPE;<br />
</strong>&#8230;</p>
<p>The beauty of this is that a change to the table definition automatically ripples through to your PL/SQL code. You don’t need to manually hunt down and change record definitions.</p>
<p>Adding a column to a table would be transparent to your PL/SQL code, as<br />
would certain types of datatype changes. However, if you drop a table column<br />
that your code is using, you need to visit that code and make some<br />
changes.</p>
<p>As with any other record, you use dot notation to reference a specific field. As far as PL/SQL is concerned, using department%ROWTYPE has the same effect as if you had declared the record like this:</p>
<p><strong> DECLARE<br />
TYPE dept_type IS RECORD<br />
(<br />
dept_id department.dept_id%type,<br />
dept_name department.dept_name%type,<br />
no_of_emps department.no_of_emps%type<br />
);<br />
</strong></p>
<p><strong>dept dept_type;</strong></p>
<p>If you’re working with all or most of the fields in a table, use %ROWTYPE to declare your records. You’ll save typing, and you’ll insulate your code somewhat from changes to the table.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.technooracle.com/oracle-tutorials/using-records-on-tables-in-oracle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle PL SQL:Records</title>
		<link>http://www.technooracle.com/oracle-tutorials/records-in-oracle-plsql/</link>
		<comments>http://www.technooracle.com/oracle-tutorials/records-in-oracle-plsql/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 07:54:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Records in Oracle]]></category>
		<category><![CDATA[Records in PL SQL]]></category>
		<category><![CDATA[Records in PL/SQL]]></category>
		<category><![CDATA[Records in SQL]]></category>
		<category><![CDATA[Using the %TYPE Attribute in Records]]></category>

		<guid isPermaLink="false">http://www.technooracle.com/?p=293</guid>
		<description><![CDATA[Records are a PL/SQL composite datatype.A record is a collection of individual values that are related somehow. Most often, records are used to represent a row in a table, and thus the relationship is based on all the values being from the same row. Each field in a record is unique and has its own [...]]]></description>
			<content:encoded><![CDATA[<p>Records are a PL/SQL composite datatype.A record is a collection of individual values that are related somehow. Most often, records are used to represent a row in a table, and thus the relationship is based on all the values being from the same row. Each field in a record is unique and has its own values.A record as a whole does not have a value.</p>
<p>By using records, you can group like data into one structure and then manipulate this structure as one entity or logical unit. This helps reduce coding and keeps the code easier to maintain and understand.</p>
<h2><span style="color: #000080;">Declaring a Record Variable</span></h2>
<p>In order to use a record, you must define the record by declaring a record type. Then,you must declare one or more PL/SQL variables to be of that type.</p>
<p>You declare a record type in the declaration portion of a PL/SQL block, subprogram, or package.<br />
<span id="more-293"></span><br />
The following example declares a record type named emp_pay_salary:</p>
<p><strong>TYPE emp_pay_salary IS RECORD &#8211;record declaration<br />
(emp_id INTEGER(10),<br />
emp_name VARCHAR2(32),<br />
emp_sal NUMBER(9,2),<br />
sal_type CHAR(1)<br />
);</strong></p>
<p>With the record type defined, you can then declare variables of that type, as in the following</p>
<p>example:<br />
DECLARE<br />
&#8230;<br />
emp emp_pay_info;<br />
&#8230;<br />
BEGIN<br />
&#8230;<br />
After you have a record variable declared, you can use dot notation to reference the individual fields within the record. In the following example, the pay_type field in the emp record is referenced in an IF statement:</p>
<p>IF emp.sal_type = ‘S’ THEN&#8230;</p>
<p>Having related fields grouped together in a record allows you to more easily keep things together when you are passing those values as parameters to other program units.</p>
<p>This example shows the declaration for a procedure that takes a record of type emp_pay_info as a parameter:</p>
<p>procedure calculate_check (emp IN emp_pay_info) IS<br />
&#8230;<br />
Passing related values as a record not only makes your code more readable, but it makes it more maintainable as well. If you need to add another field to the emp_pay_info record, you only need to change the record definition, and that new value will be passed around everywhere that the record goes. If you were dealing with separate variables, you would have to change the header for every procedure and function that used the record.</p>
<h2><span style="color: #000080;">Using the %TYPE Attribute in Records<br />
</span></h2>
<p>If you’re declaring a record, and you want some of the field definitions to match definitions of columns in a database table, you can use the %TYPE attribute.To declare a variable to match a column definition, place an entry such as this in the declaration section of the PL/SQL block:</p>
<p><strong>variable_name table_name.column_name%TYPE;</strong></p>
<p>The %TYPE following the table and column name tells Oracle that you want the variable being declared to inherit its datatype and length from the definition of the named column.</p>
<p>The following example shows another way to define the emp_pay_info record<br />
shown in the previous section:</p>
<p>TYPE emp_pay_salary IS RECORD<br />
(emp_id employee.emp_id%TYPE,<br />
emp_name employee.emp_name%TYPE,<br />
sal_rate employee.pay_rate%TYPE,<br />
sal_type employee.pay_type%TYPE<br />
);</p>
<p>Using %TYPE like this helps insulate your PL/SQL code from changes in the underlying database columns. In the next section you’ll learn an even easier technique, using %ROWTYPE, that you can use when you want the record to contain fields for all columns in a table.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.technooracle.com/oracle-tutorials/records-in-oracle-plsql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

