錯(cuò)誤的,對(duì)于oracle而言,雙引號(hào)
要用單引號(hào),可用
可以用ASCII碼處理,其它特殊字符如&也一樣,如
insert into t values('i'||chr(39)||'m'); -- chr(39)代表字符'
或者用兩個(gè)單引號(hào)表示一個(gè)
or insert into t values('I''m'); -- 兩個(gè)''可以表示一個(gè)'
SELECT 'select segment_name,sum(bytes) FROM dba_segments WHERE owner ='|| chr(39)||'TESTBAR'||chr(39)||' AND segment_type ='||chr(39)||'TABLE'||chr(39)||' AND segment_name = '|| chr(39)||table_name||chr(39)||';' from user_tables;
注意,對(duì)于分區(qū)表要采用"TABLE PARTITION"方式
SQL> set linesize 300
SQL> set head off
SQL> spool 1.sql
exec statement
SQL>spool off
處理空行問題:
采用excel的自動(dòng)篩選進(jìn)行空行過濾!以及計(jì)算空間總和。
實(shí)用考慮:
0 產(chǎn)生行一例
select 'SELECT sum(bytes)/1024/1024 Mbytes FROM user_segments WHERE segment_type = '||chr(39)||'TABLE'||chr(39)||' AND segment_name = '||chr(39)||segment_name||chr(39)||';' from user_segments where segment_type='TABLE';
0、查看用戶表、索引、分區(qū)表占用空間
select segment_name, sum(bytes)/1024/1024 Mbytese from user_segments group by segment_name;
1、表占用空間
select segment_name, sum(bytes)/1024/1024 Mbytese from user_segments where segment_type='TABLE' group by segment_name;
2、索引占用空間select segment_name ,sum(bytes)/1024/1024 from user_segments where segment_type ='INDEX' group by segment_name;
3、分區(qū)表TABLE PARTITION占用空間
select segment_name,sum(bytes)/1024/1024 Mbytes from user_segments where segment_type='TABLE PARTITION' group by segment_name;