Trafodion 이 메타 데이터 시트 에서 필드 정 보 를 얻 는 것 에 대한 총 결
--
DROP TABLE IF EXISTS aaa;
CREATE TABLE aaa (
a NUMERIC(18, 8),
b varchar2(10),
c INT,
d largeint,
e CLOB,
f DATE,
g TIMESTAMP(6),
h NUMERIC(20, 10),
PRIMARY KEY (a, b)
);
CREATE UNIQUE INDEX idx_aaa ON aaa (c, d);
COMMENT ON TABLE aaa IS ' aaa ';
COMMENT ON COLUMN aaa.a IS ' a ';
COMMENT ON COLUMN aaa.b IS ' b ';
COMMENT ON COLUMN aaa.c IS ' c ';
COMMENT ON COLUMN aaa.d IS ' d ';
COMMENT ON COLUMN aaa.e IS ' e ';
COMMENT ON COLUMN aaa.f IS ' f ';
COMMENT ON COLUMN aaa.g IS ' g ';
COMMENT ON COLUMN aaa.h IS ' h ';
1. 필드 상세 정보 가 져 오기
SQL 구문
SELECT a.schema_name, a.object_name AS table_name, b.column_name, b.sql_data_type AS data_type, b.column_size AS data_length
, b.column_precision AS data_precision, b.nullable, b.column_number AS column_id, b.column_scale AS data_scale
, CASE
WHEN c.column_name IS NOT NULL THEN 'Y'
ELSE 'N'
END AS is_pk
, CASE
WHEN g.column_name IS NOT NULL THEN 'Y'
ELSE 'N'
END AS is_unique
, h.text AS comments
FROM "_MD_".objects a
INNER JOIN "_MD_".columns b ON a.object_uid = b.object_uid
LEFT JOIN "_MD_".keys c
ON b.object_uid = c.object_uid
AND b.column_name = c.column_name
LEFT JOIN (SELECT d.base_table_uid, rtrim(f.column_name,'@') AS column_name
FROM "_MD_".indexes d
INNER JOIN "_MD_".objects e ON d.index_uid = e.object_uid
INNER JOIN "_MD_".columns f ON e.object_uid = f.object_uid
WHERE d.is_unique = 1
AND f.column_name <> 'SYSKEY') g
ON a.object_uid = g.base_table_uid
AND b.column_name = g.column_name
LEFT JOIN "_MD_".text h
ON b.object_uid = h.text_uid
AND b.column_number = h.sub_id
AND h.text_type = 12
WHERE a.schema_name NOT LIKE '|_BACKUP|_%%|_' ESCAPE '|'
AND a.schema_name NOT IN ('_MD_', '_PRIVMGR_MD_', '_REPOS_', '_LIBMGR_')
AND a.object_type IN ('BT')
AND a.object_name NOT IN ('SB_HISTOGRAMS', 'SB_HISTOGRAM_INTERVALS', 'SB_PERSISTENT_SAMPLES')
AND b.column_name <> 'SYSKEY'
AND a.schema_name = 'SEABASE'
AND a.object_name = 'AAA'
;
샘플 출력
SCHEMA_NAME
TABLE_NAME
COLUMN_NAME
DATA_TYPE
DATA_LENGTH
DATA_PRECISION
NULLABLE
COLUMN_ID
DATA_SCALE
IS_PK
IS_UNIQUE
COMMENTS
SEABASE
AAA
A
SIGNED LARGEINT
8
18
0
0
8
Y
Y
필드 a 의 주석
SEABASE
AAA
H
SIGNED NUMERIC
10
20
1
7
10
N
N
필드 h 주석
SEABASE
AAA
G
DATETIME
11
0
1
6
6
N
N
필드 g 주석
SEABASE
AAA
F
DATETIME
4
0
1
5
0
N
N
필드 f 의 주석
SEABASE
AAA
E
CLOB
1024
1
1
4
1073741824
N
N
필드 e 의 주석
SEABASE
AAA
D
SIGNED LARGEINT
8
0
1
3
0
N
Y
필드 d 주석
SEABASE
AAA
C
SIGNED INTEGER
4
0
1
2
0
N
Y
필드 c 의 주석
SEABASE
AAA
B
VARCHAR
10
0
0
1
0
Y
Y
필드 b 의 주석
2. 홈 키 필드 정보 가 져 오기
SQL 구문
SELECT a.schema_name, a.object_name AS table_name, b.column_name
, CASE
WHEN c.column_name IS NOT NULL THEN 'Y'
ELSE 'N'
END AS is_pk
FROM "_MD_".objects a
INNER JOIN "_MD_".columns b ON a.object_uid = b.object_uid
LEFT JOIN "_MD_".keys c
ON b.object_uid = c.object_uid
AND b.column_name = c.column_name
WHERE a.schema_name NOT LIKE '|_BACKUP|_%%|_' ESCAPE '|'
AND a.schema_name NOT IN ('_MD_', '_PRIVMGR_MD_', '_REPOS_', '_LIBMGR_')
AND a.object_type IN ('BT')
AND a.object_name NOT IN ('SB_HISTOGRAMS', 'SB_HISTOGRAM_INTERVALS', 'SB_PERSISTENT_SAMPLES')
AND b.column_name <> 'SYSKEY'
AND c.column_name IS NOT NULL
AND a.schema_name = 'SEABASE'
AND a.object_name = 'AAA'
;
샘플 출력
SCHEMA_NAME
TABLE_NAME
COLUMN_NAME
IS_PK
SEABASE
AAA
A
Y
SEABASE
AAA
B
Y
3. 고정 테이블 이름 이 있 는 schema 가 져 오기
SQL 구문
SELECT a.schema_name
FROM "_MD_".objects a
WHERE a.object_name = 'AAA'
;
샘플 출력
SCHEMA_NAME
SEABASE
4. 지 정 된 shema 이름 가 져 오기
SQL 구문
SELECT distinct a.schema_name
FROM "_MD_".objects a
WHERE a.schema_name = 'V7DEV'
;
샘플 출력
SCHEMA_NAME
V7DEV
5. 고정 표 이름 의 필드 에 유일한 정 보 를 가 져 올 지 여부
SQL 구문
SELECT a.schema_name, a.object_name AS table_name, b.column_name
, CASE
WHEN instr(g.column_list, b.column_name) > 0 THEN 'Y'
ELSE 'N'
END AS is_unique
FROM "_MD_".objects a
INNER JOIN "_MD_".columns b ON a.object_uid = b.object_uid
LEFT JOIN "_MD_".keys c
ON b.object_uid = c.object_uid
AND b.column_name = c.column_name
LEFT JOIN seabase.tbl_column_list g
ON a.object_uid = g.base_table_uid
WHERE a.schema_name NOT LIKE '|_BACKUP|_%%|_' ESCAPE '|'
AND a.schema_name NOT IN ('_MD_', '_PRIVMGR_MD_', '_REPOS_', '_LIBMGR_')
AND a.object_type IN ('BT')
AND a.object_name NOT IN ('SB_HISTOGRAMS', 'SB_HISTOGRAM_INTERVALS', 'SB_PERSISTENT_SAMPLES')
AND b.column_name <> 'SYSKEY'
AND a.schema_name = 'SEABASE'
AND a.object_name = 'AAA'
;
샘플 출력
SCHEMA_NAME
TABLE_NAME
COLUMN_NAME
IS_UNIQUE
SEABASE
AAA
A
Y
SEABASE
AAA
B
Y
SEABASE
AAA
C
Y
SEABASE
AAA
D
Y
SEABASE
AAA
E
N
SEABASE
AAA
F
N
SEABASE
AAA
G
N
SEABASE
AAA
H
N
6. 고정 schema 아래 표 의 줄 수 가 져 오기
SQL 구문
-- ,
CREATE OR REPLACE FUNCTION count_rows(table_name varchar2(200),
schema_name varchar2(200)
) RETURN (rowcount INT)
AS
DECLARE
rowcount number;
stmt varchar2(2000);
BEGIN
if schema_name is null then
stmt := 'select count(*) from "' || table_name || '"';
else
stmt := 'select count(*) from "' || schema_name || '"."' || table_name || '"';
end if;
PREPARE s1 FROM stmt;
execute s1 into rowcount;
return rowcount;
END;
/
SELECT a.schema_name, a.object_name AS table_name, seabase.count_rows(a.object_name, a.schema_name) AS rowcount
FROM "_MD_".objects a
WHERE a.object_name NOT IN ('SB_HISTOGRAMS', 'SB_HISTOGRAM_INTERVALS', 'SB_PERSISTENT_SAMPLES')
AND a.object_name NOT LIKE 'LOBDescChunks%'
AND a.object_name NOT LIKE 'LOBMD%'
AND a.object_name NOT LIKE 'LOBDescHandle%'
AND a.object_type IN ('BT')
AND a.schema_name = 'SEABASE'
;
샘플 출력
SCHEMA_NAME |TABLE_NAME |ROWCOUNT
------------|----------------|---------
SEABASE |AAA |0
SEABASE |TBL_COLUMN_LIST |1347
7. 표 마다 고정된 schema 필드 목록 가 져 오기
SQL 구문
--
SELECT a.schema_name, a.object_name AS table_name, pivot(b.column_name, MAX LENGTH 10240) AS column_list
FROM "_MD_".objects a
INNER JOIN "_MD_".columns b ON a.object_uid = b.object_uid
WHERE a.schema_name NOT LIKE '|_BACKUP|_%%|_' ESCAPE '|'
AND a.schema_name NOT IN ('_MD_', '_PRIVMGR_MD_', '_REPOS_', '_LIBMGR_')
AND a.object_type IN ('BT')
AND a.object_name NOT IN ('SB_HISTOGRAMS', 'SB_HISTOGRAM_INTERVALS', 'SB_PERSISTENT_SAMPLES')
AND b.column_name <> 'SYSKEY'
AND a.schema_name = 'SEABASE'
AND a.object_name = 'AAA'
GROUP BY 1,2
;
--
SELECT a.schema_name, a.object_name AS table_name, pivot(b.column_name, MAX LENGTH 10240, ORDER BY (b.column_number)) AS column_list
FROM "_MD_".objects a
INNER JOIN "_MD_".columns b ON a.object_uid = b.object_uid
WHERE a.schema_name NOT LIKE '|_BACKUP|_%%|_' ESCAPE '|'
AND a.schema_name NOT IN ('_MD_', '_PRIVMGR_MD_', '_REPOS_', '_LIBMGR_')
AND a.object_type IN ('BT')
AND a.object_name NOT IN ('SB_HISTOGRAMS', 'SB_HISTOGRAM_INTERVALS', 'SB_PERSISTENT_SAMPLES')
AND b.column_name <> 'SYSKEY'
AND a.schema_name = 'SEABASE'
AND a.object_name = 'AAA'
GROUP BY 1,2
;
샘플 출력
SCHEMA_NAME
TABLE_NAME
COLUMN_LIST
SEABASE
AAA
A,B,C,D,E,F,G,H
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.