Oracle table space Removal Function

Source: Internet
Author: User

Create or replace procedure zzsj. trim_table (v_table_name in varchar2) is
Begin
Declare
Out_string varchar2 (9999 );
Begin
If v_table_name is not null then
Begin
-- Create Table
Select SQL _create
Into out_string
From v_trim_sybase
Where table_name = upper (v_table_name)
And rownum = 1;
Execute immediate 'create table' | out_string | '';
-- Drop table
Select SQL _drop
Into out_string
From v_trim_sybase
Where table_name = upper (v_table_name)
And rownum = 1;
Execute immediate 'drop table' | out_string | '';
-- Rename
Select SQL _rename
Into out_string
From v_trim_sybase
Where table_name = upper (v_table_name) | '_ temp'
And rownum = 1;
Execute immediate 'rename' | out_string | '';
End;
End if;
If v_table_name is null then
For cur_table in (select table_name from v_trim_sybase) loop
Begin
-- Create Table
Select SQL _create
Into out_string
From v_trim_sybase
Where table_name = upper (cur_table.table_name)
And rownum = 1;
Execute immediate 'create table' | out_string | '';
-- Drop table
Select SQL _drop
Into out_string
From v_trim_sybase
Where table_name = upper (cur_table.table_name)
And rownum = 1;
Execute immediate 'drop table' | out_string | '';
-- Rename
Select SQL _rename
Into out_string
From v_trim_sybase
Where table_name = upper (cur_table.table_name) | '_ temp'
And rownum = 1;
Execute immediate 'rename' | out_string | '';
End;
End loop;
End if;
End;
End trim_table;

========================================================== ========
Create or replace view zzsj. v_trim_sybase
Select table_name, Owner | '.' | table_name | '_ temp as select' | fun_get_columns (upper ('zzsj'), table_name) | 'from
'| Owner |'. '| table_name SQL _create,
Owner | '. '| table_name | 'purge' SQL _drop, table_name | 'to' | substr (table_name, 1, instr (table_name,' _ temp ')-1) SQL _rename from all_tables where owner = upper ('zzsj ')

========================================================== ==============

Create or replace function fun_get_columns (/* v_owner in varchar2 ,*/
V_table_name in varchar2)
Return varchar2 is
S_temp varchar2 (2000 );
Begin
S_temp: = '';
/* If upper (v_owner) = 'hzsj 'Then */
For cur_column in (select column_name
From all_tab_columns
Where table_name = lower (v_table_name );
) Loop
S_temp: = s_temp | 'trim ("'| Lower (cur_column.column_name) |
'")' | Cur_column.column_name | ',';
End loop;
Return substr (s_temp, 1, length (s_temp)-1 );
/*
Elsif upper (v_owner) = 'sybase old' then
For cur_column in (select 'trim ("'| B." name "|'") '|
Upper (B. "name") column_name
From "DBO". "sysobjects" @ tg4sybs,
"DBO". "syscolumns" @ tg4sybs B
Where a. "name" = v_table_name
And a. "ID" = B. "ID"
Order by B. "colid") loop
S_temp: = s_temp | cur_column.column_name | ',';
End loop;
Return substr (s_temp, 1, length (s_temp)-1 );

Else
For cur_column in (select '"' | column_name | '"' |
Upper (column_name) column_name
From all_tab_columns
Where table_name = v_table_name
And owner = v_owner
Order by column_id) loop
S_temp: = s_temp | cur_column.column_name | ',';
End loop;
Return substr (s_temp, 1, length (s_temp)-1 );
End if ;*/
End;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.