Live ORACLE

if you are Oracle Developer ,than this Blog most likely will make you happy.

About my Blog

This Blog particularized for Oracle Developers ... you will see interesting Codes for SQL , PL/SQL as well as new ideas for Developer Suite and Client Tools that will help you in your professional life ... and I hope I reach for your satisfaction.

About Me

I'm Hany Freedom , 25 years old , I live in EL-Minia City in Egypt , I'm Moderator at ArabOUG.org the best Arabic Forum for ORACLE on the Net. if you interested to know more about me .... just Click Here.

Assigning All the Fields of a Record in One Statement


DECLARE

-- Two identical type declarations.

TYPE deptrec1 IS RECORD(dept_num NUMBER(2),

dept_name VARCHAR2(14));

TYPE deptrec2 IS RECORD(dept_num NUMBER(2),

dept_name VARCHAR2(14));

dept1_info DEPTREC1;

dept2_info DEPTREC2;

dept3_info DEPTREC2;

BEGIN

-- Not allowed; different datatypes, even though fields are the same.

-- dept1_info := dept2_info;

-- This assignment is OK because the records have the same type.

dept2_info := dept3_info;

END;

/



You can assign a %ROWTYPE record to a user-defined record if their fields match in number and order, and corresponding fields have the same datatypes:



DECLARE

TYPE recordtyp IS RECORD(LAST employees.last_name%TYPE,

id employees.employee_id%TYPE);

CURSOR c1 IS

SELECT last_name,

employee_id

FROM employees;

-- Rec1 and rec2 have different types. But because rec2 is based on a %ROWTYPE,

-- we can assign is to rec1 as long as they have the right number of fields and

-- the fields have the right datatypes.

rec1 RECORDTYP;

rec2 c1%ROWTYPE;

BEGIN

SELECT last_name,

employee_id

INTO rec2

FROM employees

WHERE ROWNUM < 2;



rec1 := rec2;



dbms_output.Put_line('Employee #'

||rec1.id

||' = '

||rec1.LAST);

END;

/


You can also use the SELECT or FETCH statement to fetch column values into a record.
The columns in the select-list must appear in the same order as the fields in your record.


Share/Save/Bookmark

0 comments:

Post a Comment



Newer Posts Older Posts Home Page
 
http://www.dpriver.com/images/sqlpp-banner-2.png

Thanks for reading my Blog ... you Visitor Number :-