> For the complete documentation index, see [llms.txt](https://docs.tibero.com/tibero-manuals/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tibero.com/tibero-manuals/7.2.6.manuals/sql-reference-guide/data-definition-language/create-type-body.md).

# CREATE TYPE BODY

사용자 정의 타입의 바디를 정의합니다. 바디를 정의할 수 있는 타입은 오브젝트 타입으로 제한됩니다.

**CREATE TYPE BODY**의 세부 내용은 다음과 같습니다.

* **문법**

<div align="left"><figure><img src="https://content.gitbook.com/content/evqs7Ne3nMyXQFkBSQWR/blobs/gxucUre844Tfn8wrmPr9/image.png" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://content.gitbook.com/content/evqs7Ne3nMyXQFkBSQWR/blobs/L8c8MgzIwPYQo0l5Xjf0/image.png" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://content.gitbook.com/content/evqs7Ne3nMyXQFkBSQWR/blobs/S5wwYKSr2duXvoxOY4ds/image.png" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://content.gitbook.com/content/evqs7Ne3nMyXQFkBSQWR/blobs/A33prkP3r4MMl6mXrH8F/image.png" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://content.gitbook.com/content/evqs7Ne3nMyXQFkBSQWR/blobs/VpGc9Pb669tUZDo0DBA8/image.png" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://content.gitbook.com/content/evqs7Ne3nMyXQFkBSQWR/blobs/DHooGnu46GocmdNPp2m6/image.png" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://content.gitbook.com/content/evqs7Ne3nMyXQFkBSQWR/blobs/XmKASBRSEGEOuT88FIhp/image.png" alt=""><figcaption></figcaption></figure></div>

* **특권**
  * `CREATE TYPE` 시스템 특권이 있으면 자신의 스키마에 사용자 정의 타입 바디를 생성할 수 있습니다.
  * `CREATE ANY TYPE` 시스템 특권이 있으면 다른 사용자의 스키마에 사용자 정의 타입 바디를 생성할 수 있습니다.
  * `ALTER ANY TYPE` 시스템 특권이 있으면 다른 사용자의 스키마에 있는 사용자 정의 타입 바디를 변경할 수 있습니다.
* **구성요소**

– create\_type\_body

<table><thead><tr><th width="229.99993896484375">구성요소</th><th>설명</th></tr></thead><tbody><tr><td>OR REPLACE</td><td><ul><li>이미 존재하는 사용자 정의 타입 바디를 다시 정의할 때 사용</li><li>해당 타입을 재컴파일</li><li>타입을 제거 후 다시 생성하는 방식과 달리, 기존 특권이 유지됨</li></ul></td></tr><tr><td>schema</td><td><ul><li>바디를 생성할 사용자 정의 타입이 속한 스키마 이름</li><li>생략하면 현재 사용자의 스키마로 인식</li></ul></td></tr><tr><td>type_name</td><td>바디를 생성할 사용자 정의 타입 이름</td></tr><tr><td>constructor_definition</td><td><ul><li>생성자 정의부</li><li>생성자 스펙, 선언부, 실행문으로 구성</li><li>스펙은 <strong>CREATE TYPE</strong> 문에 선언된 내용과 동일해야 함</li></ul></td></tr><tr><td>map_method_definition</td><td><ul><li>맵 메소드 정의부</li><li>메소드 스펙, 선언부, 실행문으로 구성</li><li>스펙은 <strong>CREATE TYPE</strong> 문에 선언된 내용과 동일해야 함</li></ul></td></tr><tr><td>order_method_definition</td><td><ul><li>오더 메소드 정의부</li><li>메소드 스펙, 선언부, 실행문으로 구성</li><li>스펙은 <strong>CREATE TYPE</strong> 문에 선언된 내용과 동일해야 함</li></ul></td></tr><tr><td>member_method_definition</td><td><ul><li>멤버 메소드 정의부</li><li>메소드 스펙, 선언부, 실행문으로 구성</li><li>스펙은 <strong>CREATE TYPE</strong> 문에 선언된 내용과 동일해야 함</li></ul></td></tr></tbody></table>

* **예제**

다음은 **CREATE TYPE BODY** 문을 사용해 사용자 정의 타입 바디를 생성하는 예입니다.

```sql
-- CONSTRUCTOR를 가지는 TYPE BODY의 예제
DROP TYPE constructor_example;

CREATE TYPE constructor_example AS OBJECT (
    attr1 NUMBER,
    attr2 NUMBER,
    CONSTRUCTOR FUNCTION constructor_example(p1 NUMBER) RETURN SELF AS RESULT
);
/

CREATE TYPE BODY constructor_example
AS
    CONSTRUCTOR FUNCTION constructor_example(p1 NUMBER) RETURN SELF AS RESULT
AS
BEGIN
    attr1 := p1;        -- 입력값을 1번째 Attribute로 지정
    attr2 := p1 * p1;   -- 입력값의 제곱을 2번째 Attribute 값으로 지정

    RETURN;
END;
END;
/
/ 

DROP TYPE map_method_example;

CREATE TYPE map_method_example AS OBJECT (
    attr1 NUMBER,
    attr2 NUMBER,
    MAP MEMBER FUNCTION map_method_example RETURN VARCHAR
);
/

CREATE TYPE BODY map_method_example
AS
    -- 맵 메소드는 오브젝트 인스턴스로부터 스칼라 값을 하나 가져온다.
    MAP MEMBER FUNCTION map_method_example RETURN VARCHAR
    AS
    BEGIN
        RETURN TO_CHAR(attr2);
    END;
END;
/

DROP TYPE order_method_example;

CREATE TYPE order_method_example AS OBJECT  (
    attr1 NUMBER,
    attr2 NUMBER,
    ORDER MEMBER FUNCTION order_method_example(v order_method_example)
    RETURN NUMBER
);
/

CREATE TYPE BODY order_method_example
AS
    -- 오더 메소드는 두 오브젝트 타입 인스턴스를 비교해 숫자 타입을 반환한다.
    ORDER MEMBER FUNCTION order_method_example(v order_method_example)
    RETURN NUMBER
    AS
    BEGIN
        IF attr1 < v.attr1 THEN
            RETURN -1;
        ELSIF attr1 = v.attr1 THEN
            RETURN 0;
        ELSE
            RETURN 1;
        END IF;
    END;
END;
/
DROP TYPE normal_method_example;

CREATE TYPE normal_method_example AS OBJECT (
    attr1 NUMBER,
    attr2 NUMBER,
    MEMBER FUNCTION normal_function_example(value NUMBER) RETURN NUMBER,
    MEMBER PROCEDURE normal_procedure_example(SELF IN normal_method_example)
);
/
CREATE TYPE BODY normal_method_example
AS
    MEMBER FUNCTION normal_function_example(value NUMBER) RETURN NUMBER
    AS
    BEGIN
        RETURN (attr1 + attr2) * value;
    END;
    MEMBER PROCEDURE normal_procedure_example(SELF IN normal_method_example)
    AS
    BEGIN
        DBMS_OUTPUT.PUT_LINE('attribute1:' || SELF.attr1);
        DBMS_OUTPUT.PUT_LINE('attribute2:' || SELF.attr2);
    END;
END;
/
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.tibero.com/tibero-manuals/7.2.6.manuals/sql-reference-guide/data-definition-language/create-type-body.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
