Navigation: Application Developer > Application > Database > Table
Registration
--
DECLARE
vc_appl_short_name VARCHAR2 (40) := 'XXAK';
vc_tab_name VARCHAR2 (32) := 'XXAK_WEB_ADI_DOWNLAOD_TBL';
vc_tab_type VARCHAR2 (50) := 'T';
vn_next_extent NUMBER := 512; -- Default Value
vn_pct_free NUMBER := 10; -- Default Value
vn_pct_used NUMBER := 70; -- Default Value
-- Table Details
CURSOR cur_tab_details (c_tab_name varchar2)
IS
SELECT table_name
,next_extent
,pct_free
,pct_used
FROM dba_tables
WHERE table_name = c_tab_name;
-- Column Details
CURSOR cur_col_details (c_tab_name varchar2)
IS
SELECT column_name
,column_id
,data_type
,data_length
,nullable
FROM all_tab_columns
WHERE table_name = c_tab_name;
--Primary keys details
CURSOR cur_pri_key (c_tab_name varchar2)
IS
SELECT constraint_name
,table_name
FROM all_constraints
WHERE constraint_type = 'P'
AND table_name = c_tab_name;
-- primary key column details
CURSOR cur_pri_key_details (c_tab_name varchar2, c_constraint_name varchar2)
IS
SELECT column_name
,position
FROM dba_cons_columns
WHERE table_name = c_tab_name
AND constraint_name = c_constraint_name;
BEGIN
-- Register Table
-- Get the table details
FOR rec_tab_details IN cur_tab_details(vc_tab_name)
LOOP
-- Call the API to register table
ad_dd.register_table (p_appl_short_name => vc_appl_short_name,
p_tab_name => rec_tab_details.table_name,
p_tab_type => vc_tab_type,
p_next_extent => NVL(rec_tab_details.next_extent, vn_next_extent),
p_pct_free => NVL(rec_tab_details.pct_free, vn_pct_free),
p_pct_used => NVL(rec_tab_details.pct_used, vn_pct_used)
);
END LOOP; -- End Register Custom Table
-- Register Column(s)
-- Get the column details of the table
FOR rec_col_details IN cur_col_details(vc_tab_name)
LOOP
-- Call the API to register column
ad_dd.register_column (p_appl_short_name => vc_appl_short_name,
p_tab_name => vc_tab_name,
p_col_name => rec_col_details.column_name,
p_col_seq => rec_col_details.column_id,
p_col_type => rec_col_details.data_type,
p_col_width => rec_col_details.data_length,
p_nullable => rec_col_details.nullable,
p_translate => 'N',
p_precision => NULL,
p_scale => NULL
);
END LOOP; -- End Register Columns
-- Register Primary Key
-- Get the primary key detail of the table
FOR rec_pri_key IN cur_pri_key(vc_tab_name)
LOOP
-- Call the API to register primary_key
ad_dd.register_primary_key (p_appl_short_name => vc_appl_short_name,
p_key_name => rec_pri_key.constraint_name,
p_tab_name => rec_pri_key.table_name,
p_description => 'Register primary key',
p_key_type => 'S',
p_audit_flag => 'N',
p_enabled_flag => 'Y'
);
-- Register Primary Key Columns
-- Get the primary key column details
FOR rec_pri_key_details IN cur_pri_key_details (rec_pri_key.table_name,rec_pri_key.constraint_name)
LOOP
-- Call the API to register primary_key_column
ad_dd.register_primary_key_column
(p_appl_short_name => vc_appl_short_name,
p_key_name => rec_pri_key.constraint_name,
p_tab_name => rec_pri_key.table_name,
p_col_name => rec_pri_key_details.column_name,
p_col_sequence => rec_pri_key_details.position
);
END LOOP; -- End Register Primary Key Column
END LOOP; -- End Register Primary Key
COMMIT;
DBMS_OUTPUT.PUT_LINE('Table: '||vc_tab_name||' Registered');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error in Registration: '||SQLERRM);
ROLLBACK;
END;
--
Related Post: Delete Custom Table Registration
Registration
--
DECLARE
vc_appl_short_name VARCHAR2 (40) := 'XXAK';
vc_tab_name VARCHAR2 (32) := 'XXAK_WEB_ADI_DOWNLAOD_TBL';
vc_tab_type VARCHAR2 (50) := 'T';
vn_next_extent NUMBER := 512; -- Default Value
vn_pct_free NUMBER := 10; -- Default Value
vn_pct_used NUMBER := 70; -- Default Value
-- Table Details
CURSOR cur_tab_details (c_tab_name varchar2)
IS
SELECT table_name
,next_extent
,pct_free
,pct_used
FROM dba_tables
WHERE table_name = c_tab_name;
-- Column Details
CURSOR cur_col_details (c_tab_name varchar2)
IS
SELECT column_name
,column_id
,data_type
,data_length
,nullable
FROM all_tab_columns
WHERE table_name = c_tab_name;
--Primary keys details
CURSOR cur_pri_key (c_tab_name varchar2)
IS
SELECT constraint_name
,table_name
FROM all_constraints
WHERE constraint_type = 'P'
AND table_name = c_tab_name;
-- primary key column details
CURSOR cur_pri_key_details (c_tab_name varchar2, c_constraint_name varchar2)
IS
SELECT column_name
,position
FROM dba_cons_columns
WHERE table_name = c_tab_name
AND constraint_name = c_constraint_name;
BEGIN
-- Register Table
-- Get the table details
FOR rec_tab_details IN cur_tab_details(vc_tab_name)
LOOP
-- Call the API to register table
ad_dd.register_table (p_appl_short_name => vc_appl_short_name,
p_tab_name => rec_tab_details.table_name,
p_tab_type => vc_tab_type,
p_next_extent => NVL(rec_tab_details.next_extent, vn_next_extent),
p_pct_free => NVL(rec_tab_details.pct_free, vn_pct_free),
p_pct_used => NVL(rec_tab_details.pct_used, vn_pct_used)
);
END LOOP; -- End Register Custom Table
-- Register Column(s)
-- Get the column details of the table
FOR rec_col_details IN cur_col_details(vc_tab_name)
LOOP
-- Call the API to register column
ad_dd.register_column (p_appl_short_name => vc_appl_short_name,
p_tab_name => vc_tab_name,
p_col_name => rec_col_details.column_name,
p_col_seq => rec_col_details.column_id,
p_col_type => rec_col_details.data_type,
p_col_width => rec_col_details.data_length,
p_nullable => rec_col_details.nullable,
p_translate => 'N',
p_precision => NULL,
p_scale => NULL
);
END LOOP; -- End Register Columns
-- Register Primary Key
-- Get the primary key detail of the table
FOR rec_pri_key IN cur_pri_key(vc_tab_name)
LOOP
-- Call the API to register primary_key
ad_dd.register_primary_key (p_appl_short_name => vc_appl_short_name,
p_key_name => rec_pri_key.constraint_name,
p_tab_name => rec_pri_key.table_name,
p_description => 'Register primary key',
p_key_type => 'S',
p_audit_flag => 'N',
p_enabled_flag => 'Y'
);
-- Register Primary Key Columns
-- Get the primary key column details
FOR rec_pri_key_details IN cur_pri_key_details (rec_pri_key.table_name,rec_pri_key.constraint_name)
LOOP
-- Call the API to register primary_key_column
ad_dd.register_primary_key_column
(p_appl_short_name => vc_appl_short_name,
p_key_name => rec_pri_key.constraint_name,
p_tab_name => rec_pri_key.table_name,
p_col_name => rec_pri_key_details.column_name,
p_col_sequence => rec_pri_key_details.position
);
END LOOP; -- End Register Primary Key Column
END LOOP; -- End Register Primary Key
COMMIT;
DBMS_OUTPUT.PUT_LINE('Table: '||vc_tab_name||' Registered');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error in Registration: '||SQLERRM);
ROLLBACK;
END;
--
Related Post: Delete Custom Table Registration
Great post
ReplyDelete