oracle sql

Posted 无处安放的灵魂

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle sql相关的知识,希望对你有一定的参考价值。

select * from all_users; --DROP USER vkdev CASCADE; SELECT * FROM USER_TABLES; --???????????

SELECT A.TABLESPACE_NAME,FILENUM, TOTAL "TOTAL (MB)",F.FREE "FREE (MB)",TO_CHAR(ROUND(FREE * 100 / TOTAL, 2), ‘990.00‘) "FREE%", TO_CHAR(ROUND((TOTAL - FREE) * 100 / TOTAL, 2), ‘990.00‘) "USED%", ROUND(MAXSIZES, 2) "MAX (MB)" FROM (SELECT TABLESPACE_NAME, COUNT(FILE_ID) FILENUM,SUM(BYTES / (1024 * 1024)) TOTAL,SUM(MAXBYTES) / 1024 / 1024 MAXSIZES FROM DBA_DATA_FILES GROUP BY TABLESPACE_NAME) A, (SELECT TABLESPACE_NAME, ROUND(SUM(BYTES / (1024 * 1024))) FREE FROM DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) F WHERE A.TABLESPACE_NAME = F.TABLESPACE_NAME;

select /*+ ordered use_hash(a,b,c) */a.file_id,a.file_name,a.filesize, b.freesize,(a.filesize-b.freesize) usedsize,c.hwmsize, c.hwmsize - (a.filesize-b.freesize) unsedsize_belowhwm,a.filesize - c.hwmsize canshrinksize from ( select file_id,file_name,round(bytes/1024/1024) filesize from dba_data_files) a,( select file_id,round(sum(dfs.bytes)/1024/1024) freesize from dba_free_space dfs group by file_id) b, (select file_id,round(max(block_id)*8/1024) HWMsize from dba_extents group by file_id) c where a.file_id = b.file_id and a.file_id = c.file_id  order by unsedsize_belowhwm desc;

select sum(ts_sizemb) from ( select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_sizeMB from dba_tablespaces t, dba_data_files d where t.tablespace_name = d.tablespace_name  group by t.tablespace_name);

select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_sizeMB from dba_tablespaces t, dba_data_files d where t.tablespace_name = d.tablespace_name and t.tablespace_name like ‘VA%‘ group by t.tablespace_name;

SELECT   owner, tablespace_name, ROUND (SUM (BYTES) / 1024 / 1024, 2) "USED(M)" FROM dba_segments GROUP BY owner, tablespace_name ORDER BY SUM (BYTES) DESC; --ALTER DATABASE DATAFILE ‘C:\ORACLEXE\APP\ORACLE\ORADATA\XE\SYSTEM.DBF‘ RESIZE 9048M; --query space count from data files select tablespace_name, file_id, file_name,round(bytes/(1024*1024),0) total_space from dba_data_files order by tablespace_name; select tablespace_name, file_id, file_name, round(bytes/(1024*1024),0) total_space from dba_temp_files order by tablespace_name; --query space count from dba_free_space select sum(bytes)/(1024*1024) as free_space,tablespace_name from dba_free_space group by tablespace_name; SELECT * from DBA_TEMP_FREE_SPACE; --??/??Database?Default Temporary Tablespace SELECT PROPERTY_NAME, PROPERTY_VALUE FROM DATABASE_PROPERTIES WHERE PROPERTY_NAME=‘DEFAULT_TEMP_TABLESPACE‘; --ALTER DATABASE DEFAULT TEMPORARY TABLESPACE tablespace_name; select sum(bytes)/1024/1024 "???(M)" from user_segments where segment_name=‘table_name‘;--????????????????? -- partition SELECT TABLE_NAME, PARTITION_NAME, HIGH_VALUE FROM USER_TAB_PARTITIONS  WHERE TABLE_NAME = ‘T_INTERVAL_NUMBER‘  ORDER BY 2;

select owner, db_link from dba_db_links;

select * from dba_directories;

select * from dba_role_privs connect by prior granted_role = grantee start with grantee = ‘VKC2‘ order by 1,2,3; select * from dba_sys_privs  where grantee = ‘VKC2‘ or grantee in (select granted_role from dba_role_privs connect by prior granted_role = grantee start with grantee = ‘VKC2‘) order by 1,2,3; select * from dba_tab_privs  where grantee = ‘VKC2‘ or grantee in (select granted_role from dba_role_privs connect by prior granted_role = grantee start with grantee = ‘VKC2‘) order by 1,2,3,4;

select * from table(RDSADMIN.RDS_FILE_UTIL.LISTDIR(‘DMP‘)) order by mtime; select * from table(RDSADMIN.RDS_FILE_UTIL.LISTDIR(‘DATA_PUMP_DIR‘)) order by mtime; exec utl_file.fremove(‘DATA_PUMP_DIR‘,‘BEIJING_EXPDP_VKC_2016-05-10-09-08-49.DMP.log‘);

drop public database link to_rds create public database link to_rds connect to vkc2 identified by vkc2 using ‘ONNVLQ01‘     DBMS_FILE_TRANSFER.PUT_FILE(‘DMP‘,  ‘EXPDP_VKC.DMP‘,‘DMP‘,‘EXPDP_VKC_20151020.DMP‘,  ‘to_rds‘ );

--START CBO alter system flush buffer_cache analyze table RELIEFD compute statistics --exec dbms_stats.gather_table_stats(user,‘xiaogongjiang‘);

 

--END CBO

--ALTER TABLE RELIEFD ADD MISCCOST_TMP NUMBER(22,0); --ALTER TABLE RELIEFD ADD MISCCOST_TMP_TMP NUMBER(22,0); --ALTER TABLE RELIEFD ADD MISCCOST_TMP_TMP_TMP NUMBER(22,0); --ALTER TABLE RELIEFD DROP COLUMN MISCCOST_TMP; --ALTER TABLE RELIEFD DROP COLUMN MISCCOST_TMP_TMP; --ALTER TABLE RELIEFD DROP COLUMN MISCCOST_TMP_TMP_TMP;

--expdp vkc2/[email protected] directory=DATA_PUMP_DIR dumpfile=bk_vkc_20160712.dmp logfile=bk_vkc_20160712.log --exp vkc2/[email protected] FILE=VKC_20160712.dmp LOG=VKC_20160712.log tables=(AVMODEL,COUNTRIES,DEFAULTUNITS,FIELDDEFINITION,FIELDMENU,FIELDMENUITEMS,FLP,GRIDCALCULATIONFIELD,GRIDCUSTOMIZEDFIELD,GRIDDEFAULTFIELD,GRIDDISPLAYFIELD,GRIDFILTER,GRIDLEFTFIELD,GRIDSORTFIELD,GRIDSHAREDFIELD,GTCLINKS,HOTLINK,INTERNALS,MDCRDM,MDPARTL,PARTSFILTERSETTINGS,REGIONCOUNTRY,REGIONS,RVSPRINGCHART,STATES,TEMPLATES,TENANT,TENANTSETTINGS,TRAVELLERCRITICALDIMENSIONS,TRAVELLERTYPES,TRAVELLERPARTS,TRAVELLERQCCHECKLIST,UMODEL,USERCONTROLSTATE,USERID,UNITS,USERPREFERENCE,VKPERMISSION,VKOPERATION,VKROLE,VKRESOURCE,VKUSER,VKUSERROLE)

--impdp vkc2/[email protected] DUMPFILE=bk_vkc_20160712.dmp DIRECTORY=DMP full=y create public database link to_rdsp connect to vkc2 identified by vkcl0ud  using ‘(DESCRIPTION_LIST= (LOAD_BALANCE=OFF) (FAILOVER=ON) (DESCRIPTION= (SOURCE_ROUTE=yes) (ADDRESS=    (PROTOCOL=tcp)(HOST=us1.ocm.og.vpc.ge.com)(PORT=80))        (ADDRESS=(PROTOCOL=tcp)(HOST=onnvlp01.cka5zavzaj22.us-east-1.rds.amazonaws.com)(PORT=1521)) (CONNECT_DATA=(SERVICE_NAME = ONNVLP01)))    (DESCRIPTION= (SOURCE_ROUTE=yes) (ADDRESS=    (PROTOCOL=tcp)(HOST=us2.ocm.og.vpc.ge.com)(PORT=80))        (ADDRESS=(PROTOCOL=tcp)(HOST=onnvlp01.cka5zavzaj22.us-east-1.rds.amazonaws.com)(PORT=1521)) (CONNECT_DATA=(SERVICE_NAME = ONNVLP01))))‘                             create database link to_rdsq connect to vkc2 identified by vkc2 using ‘(DESCRIPTION_LIST= (LOAD_BALANCE=OFF) (FAILOVER=ON) (DESCRIPTION= (SOURCE_ROUTE=yes) (ADDRESS=                 (PROTOCOL=tcp)(HOST=us1.ocm.og.vpc.ge.com)(PORT=80))                                 (ADDRESS=(PROTOCOL=tcp)(HOST=onnvlq01.cka5zavzaj22.us-east-1.rds.amazonaws.com)(PORT=1521)) (CONNECT_DATA=(SERVICE_NAME = ONNVLQ01)))                 (DESCRIPTION= (SOURCE_ROUTE=yes) (ADDRESS=                 (PROTOCOL=tcp)(HOST=us2.ocm.og.vpc.ge.com)(PORT=80))                                 (ADDRESS=(PROTOCOL=tcp)(HOST=onnvlq01.cka5zavzaj22.us-east-1.rds.amazonaws.com)(PORT=1521)) (CONNECT_DATA=(SERVICE_NAME = ONNVLQ01))))‘                                             BEGIN   DBMS_FILE_TRANSFER.GET_FILE(     source_directory_object       => ‘DATA_PUMP_DIR‘,     source_file_name              => ‘bk_vkc_20160712.dmp‘,     source_database          => ‘to_rdsp‘,     destination_directory_object  => ‘DATA_PUMP_DIR‘,     destination_file_name         => ‘bk_vkc_20160712.dmp‘   ); END;

                                BEGIN   DBMS_FILE_TRANSFER.PUT_FILE(     source_directory_object       => ‘DATA_PUMP_DIR‘,     source_file_name              => ‘bk_vkc_20160712.dmp‘,     destination_directory_object  => ‘DATA_PUMP_DIR‘,     destination_file_name         => ‘bk_vkc_20160712.dmp‘,     destination_database          => ‘to_rdsq‘   ); END;

以上是关于oracle sql的主要内容,如果未能解决你的问题,请参考以下文章

日期比较返回异常结果 - SQL Oracle

在sql oracle中的情况

SQL Oracle .. 更新表的最新值

使用sql oracle计算地理点之间的距离

(SQL ORACLE)如何生成 html 输出,给定 select 语句?

为啥在 PL/SQL Oracle 中尝试创建 INSTEAD OF 触发器时出现“错误的绑定变量”错误?