Oracle Custom Data Type

Introduction
This month, the project implemented a dynamic summary and exported to Excel. Mom, in order to achieve this function, a grid page used 20+ stored procedures and custom functions, and finally completed the preliminary test work, which I have almost run out of Oracle knowledge that I have not mastered, including row to column (XML), column to row, dynamic table, dynamic SQL, custom Type, pipeline function, data flow function, etc., in order to deepen the impression, It is convenient to sort out your own knowledge system and give some help to some people in need. Let's start with a custom data type.

The types of Oracle custom types are the
record data type (Record) and the record table type (Table), where the record data type Record is a record, and the record table type Table is used to store multiple records. If the record data type Record is a one-dimensional array, the record table type Table is a two-dimensional array.

There are two ways to write a custom type: TYPE …… IS and CREATE TYPE ……, the difference between the two is that the former is generally defined in stored procedures and functions, the scope is the process or function, and the latter declares the object type It is used as a database object (like a table, index, view, trigger, a database object), can be used in procedures or functions, and can also be used as the field type when defining tables.

First, TYPE type_name IS RECORD defines the record data type
definition syntax:

TYPE type_name IS RECORD ( 
              field name 1 database variable type 1, 
              field name 2 database variable type 2, 
              ... 
              field name n database variable type n 
      ); 
      where type_name: the name of the custom type

Application examples

DECLARE 
  TYPE type_Employee IS RECORD(
          name VARCHAR2(100),
          age  NUMBER(3),
          wage NUMBER(7,2)
  );

  v_employs type_Employee;
  v_name VARCHAR2(100);
  v_age  NUMBER(3);
  v_wage NUMBER(7,2);
  i integer;
BEGIN
  select name, age, wage into v_employs from Employees where EmployeesId = '750adfd0-f8cd-4a64-a2f8-736f8802ec87';
  v_name := v_employs.name;
  v_age := v_employs.age;
  v_wage := v_employs.wage;
  dbms_output.put_line(v_name);
  dbms_output.put_line(v_wage);
  dbms_output.put_line(v_age);
END;

 

Guess you like

Origin www.cnblogs.com/yuanshuo/p/12691303.html