레코드란?

Records are another type of datatypes which oracle allows to be defined as a placeholder. Records are composite datatypes, which means it is a combination of different scalar datatypes like char, varchar, number etc.  Each scalar data types in the record holds a value. A record can be visualized as a row of data. It can contain all the contents of a row.

 

레코드 선언 

To declare a record, you must first define a composite datatype; then declare a record for that type.

 

 

일반적인 구문에 복합데이터유형 선언

 

TYPE record_type_name IS RECORD

(first_col_name column_datatype,

second_col_name column_datatype, ...);

 

record_type_name – 정의한 복합유형에 이름

first_col_name, second_col_name, etc.,- 레코드 내에 필드와 열 이름

column_datatype 은 필드에 스칼라데이터타입유형을 정의한다.

 

 


There are different ways you can declare the datatype of the fields.

1) You can declare the field in the same way as you declare the fieds while creating the table.
2) If a field is based on a column from database table, you can define the field_type as follows:

col_name table_name.column_name%type; 
NOTE: You can use also %type to declare variables and constants.

 

 

다음의 코드는 사용자정의유형 기반에 employee_rec 기록하고 선언하는 방법을 보여준다.

DECLARE 
TYPE employee_type IS RECORD 
(employee_id number(5), 
 employee_first_name varchar2(25), 
 employee_last_name employee.last_name%type, 
 employee_dept employee.dept%type); 
 employee_salary employee.salary%type;
 employee_rec employee_type; 

 

만약 모든 필드가 테이블 열 기반으로 기록 됬다면, 기록하고 선언 할 수 있는 방법은 다음과 같다.

 

record_name table_name%ROWTYPE; 

 

예를들어, 위 employee_rec을 선언 하는 방법은 다음과같다.

 

DECLARE 
 employee_rec employee%ROWTYPE; 

RECORD를 ROWTYPE으로 선언 했을 떄 장점
1. 모든 테이블안에 열대한 변수선언을 명시적으로 할 필요없다.
2. 데이터베이스 테이블안에 열사양을 변경하려고 할때, 코드를 업데이트 할 필요가 없다.
RECORD를 ROWTYPE으로 선언 했을 때 단점
1. RECORD에 ROWTYPE생성 시 , 필드 생성에대한 테이블안에 모든 열과 모든필드에 대한 데이터유형 생성에 사용된 메모리. 그래서 프로그램 안에있는 테이블에 모든 열이 사용 될때만 ROWTYPE을 사용.
 
RECORD생성 시, 데이터유형을 항상 생성하고, 변수를 생성하는 것과 비슷하다. 레코드는 사용할때 값을 지정해야된다 필요한만큼.
 
 
 
 
 

 

'데이터베이스 > PL/SQL' 카테고리의 다른 글

PL/SQL SelectQuery/alias column(to_char())  (0) 2015.11.09
PL/SQL SelctQuery/alias column(계산된 열에대한 머릿글)  (0) 2015.11.09
PL/SQL CONSTANT  (0) 2015.11.09
PL/SQL Variable  (0) 2015.11.09
PL/SQL PROCEDURE 생성  (0) 2015.11.08
블로그 이미지

왕왕왕왕

,