oracle常用命令大全
oracle11g常用命令

第一章:日志管理1.forcing log switchessql> alter system switch logfile;2.forcing checkpointssql> alter system checkpoint;3.adding online redo log groupssql> alter database add logfile [group 4]sql> ('/disk3/log4a.rdo','/disk4/log4b.rdo') size 1m;4.adding online redo log memberssql> alter database add logfile membersql> '/disk3/log1b.rdo' to group 1,sql> '/disk4/log2b.rdo' to group 2;5.changes the name of the online redo logfilesql> alter database rename file 'c:/oracle/oradata/oradb/redo01.log' sql> to 'c:/oracle/oradata/redo01.log';6.drop online redo log groupssql> alter database drop logfile group 3;7.drop online redo log memberssql> alter database drop logfile member 'c:/oracle/oradata/redo01.log';8.clearing online redo log filessql> alter database clear [unarchived] logfile 'c:/oracle/log2a.rdo';ing logminer analyzing redo logfilesa. in the init.ora specify utl_file_dir = ' 'b. sql> executedbms_logmnr_d.build('oradb.ora','c:\oracle\oradb\log');c. sql> executedbms_logmnr_add_logfile('c:\oracle\oradata\oradb\redo01.log',sql> dbms_logmnr.new);d. sql> executedbms_logmnr.add_logfile('c:\oracle\oradata\oradb\redo02.log',sql> dbms_logmnr.addfile);e. sql> executedbms_logmnr.start_logmnr(dictfilename=>'c:\oracle\oradb\log\oradb.ora ');f. sql> select * fromv$logmnr_contents(v$logmnr_dictionary,v$logmnr_parameterssql> v$logmnr_logs);g. sql> execute dbms_logmnr.end_logmnr;第二章:表空间管理1.create tablespacessql> create tablespace tablespace_name datafile'c:\oracle\oradata\file1.dbf' size 100m,sql> 'c:\oracle\oradata\file2.dbf' size 100m minimum extent 550k [logging/nologging]sql> default storage (initial 500k next 500k maxextents 500 pctinccease 0)sql> [online/offline] [permanent/temporary] [extent_management_clause]2.locally managed tablespacesql> create tablespace user_data datafile'c:\oracle\oradata\user_data01.dbf'sql> size 500m extent management local uniform size 10m;3.temporary tablespacesql> create temporary tablespace temp tempfile'c:\oracle\oradata\temp01.dbf'sql> size 500m extent management local uniform size 10m;4.change the storage settingsql> alter tablespace app_data minimum extent 2m;sql> alter tablespace app_data default storage(initial 2m next 2m maxextents 999);5.taking tablespace offline or onlinesql> alter tablespace app_data offline;sql> alter tablespace app_data online;6.read_only tablespacesql> alter tablespace app_data read only|write;7.droping tablespacesql> drop tablespace app_data including contents;8.enableing automatic extension of data filessql> alter tablespace app_data add datafile'c:\oracle\oradata\app_data01.dbf'size 200msql> autoextend on next 10m maxsize 500m;9.change the size fo data files manuallysql> alter database datafile 'c:\oracle\oradata\app_data.dbf'resize 200m;10.Moving data files: alter tablespacesql> alter tablespace app_data rename datafile'c:\oracle\oradata\app_data.dbf'sql> to 'c:\oracle\app_data.dbf';11.moving data files:alter databasesql> alter database rename file 'c:\oracle\oradata\app_data.dbf'sql> to 'c:\oracle\app_data.dbf';第三章:表1.create a tablesql> create table table_name (column datatype,column datatype]....) sql> tablespace tablespace_name [pctfree integer] [pctused integer] sql> [initrans integer] [maxtrans integer]sql> storage(initial 200k next 200k pctincrease 0 maxextents 50)sql> [logging|nologging] [cache|nocache]2.copy an existing tablesql> create table table_name [logging|nologging] as subquery3.create temporary tablesql> create global temporary table xay_temp as select * from xay;on commit preserve rows/on commit delete rows4.pctfree = (average row size - initial row size) *100 /average row size pctused = 100-pctfree- (average row size*100/available data space)5.change storage and block utilization parametersql> alter table table_name pctfree=30 pctused=50 storage(next 500k sql> minextents 2 maxextents 100);6.manually allocating extentssql> alter table table_name allocate extent(size 500k datafile'c:/oracle/data.dbf');7.move tablespacesql> alter table employee move tablespace users;8.deallocate of unused spacesql> alter table table_name deallocate unused [keep integer]9.truncate a tablesql> truncate table table_name;10.drop a tablesql> drop table table_name [cascade constraints];11.drop a columnsql> alter table table_name drop column comments cascade constraints checkpoint 1000;alter table table_name drop columns continue;12.mark a column as unusedsql> alter table table_name set unused column comments cascade constraints;alter table table_name drop unused columns checkpoint 1000;alter table orders drop columns continue checkpoint 1000data_dictionary : dba_unused_col_tabs第四章:索引1.creating function-based indexessql> create index summit.item_quantity onsummit.item(quantity-quantity_shipped);2.create a B-tree indexsql> create [unique] index index_name on table_name(column,.. asc/desc) tablespacesql> tablespace_name [pctfree integer] [initrans integer] [maxtrans integer]sql> [logging | nologging] [nosort] storage(initial 200k next 200k pctincrease 0sql> maxextents 50);3.pctfree(index)=(maximum number of rows-initial number ofrows)*100/maximum number of rows4.creating reverse key indexessql> create unique index xay_id on xay(a) reverse pctfree 30storage(initial 200ksql> next 200k pctincrease 0 maxextents 50) tablespace indx;5.create bitmap indexsql> create bitmap index xay_id on xay(a) pctfree 30 storage( initial 200k next 200ksql> pctincrease 0 maxextents 50) tablespace indx;6.change storage parameter of indexsql> alter index xay_id storage (next 400k maxextents 100);7.allocating index spacesql> alter index xay_id allocate extent(size 200k datafile'c:/oracle/index.dbf');8.alter index xay_id deallocate unused;第五章:约束1.define constraints as immediate or deferredsql> alter session set constraint[s] = immediate/deferred/default;set constraint[s] constraint_name/all immediate/deferred;2. sql> drop table table_name cascade constraintssql> drop tablespace tablespace_name including contents cascade constraints3. define constraints while create a tablesql> create table xay(id number(7) constraint xay_id primary key deferrablesql> using index storage(initial 100k next 100k) tablespace indx);primary key/unique/references table(column)/check4.enable constraintssql> alter table xay enable novalidate constraint xay_id;5.enable constraintssql> alter table xay enable validate constraint xay_id;第六章:LOAD数据1.loading data using direct_load insertsql> insert /*+append */ into emp nologgingsql> select * from emp_old;2.parallel direct-load insertsql> alter session enable parallel dml;sql> insert /*+parallel(emp,2) */ into emp nologgingsql> select * from emp_old;ing sql*loadersql> sqlldr scott/tiger \sql> control = ulcase6.ctl \sql> log = ulcase6.log direct=true第七章:reorganizing dataing expoty$exp scott/tiger tables(dept,emp) file=c:\emp.dmp log=exp.log compress=n direct=ying import$imp scott/tiger tables(dept,emp) file=emp.dmp log=imp.log ignore=y3.transporting a tablespacesql>alter tablespace sales_ts read only;$exp sys/.. file=xay.dmp transport_tablespace=y tablespace=sales_tstriggers=n constraints=n$copy datafile$imp sys/.. file=xay.dmp transport_tablespace=ydatafiles=(/disk1/sles01.dbf,/disk2/sles02.dbf)sql> alter tablespace sales_ts read write;4.checking transport setsql> DBMS_tts.transport_set_check(ts_list=>'sales_ts' ..,incl_constraints=>true);在表transport_set_violations 中查看sql> dbms_tts.isselfcontained 为true 是,表示自包含第八章: managing password security and resources1.controlling account lock and passwordsql> alter user juncky identified by oracle account unlock;er_provided password functionsql> function_name(userid in varchar2(30),password in varchar2(30),old_password in varchar2(30)) return boolean3.create a profile : password settingsql> create profile grace_5 limit failed_login_attempts 3sql> password_lock_time unlimited password_life_time 30sql>password_reuse_time 30 password_verify_function verify_function sql> password_grace_time 5;4.altering a profilesql> alter profile default failed_login_attempts 3sql> password_life_time 60 password_grace_time 10;5.drop a profilesql> drop profile grace_5 [cascade];6.create a profile : resource limitsql> create profile developer_prof limit sessions_per_user 2sql> cpu_per_session 10000 idle_time 60 connect_time 480;7. view => resource_cost : alter resource costdba_Users,dba_profiles8. enable resource limitssql> alter system set resource_limit=true;第九章:Managing users1.create a user: database authenticationsql> create user juncky identified by oracle default tablespace users sql> temporary tablespace temp quota 10m on data password expire sql> [account lock|unlock] [profile profilename|default];2.change user quota on tablespacesql> alter user juncky quota 0 on users;3.drop a usersql> drop user juncky [cascade];4. monitor userview: dba_users , dba_ts_quotas第十章:managing privileges1.system privileges: view =>system_privilege_map ,dba_sys_privs,session_privs2.grant system privilegesql> grant create session,create table to managers;sql> grant create session to scott with admin option;with admin option can grant or revoke privilege from any user or role;3.sysdba and sysoper privileges:sysoper: startup,shutdown,alter database open|mount,alter database backup controlfile,alter tablespace begin/end backup,recover databasealter database archivelog,restricted sessionsysdba: sysoper privileges with admin option,create database,recover database until4.password file members: view:=> v$pwfile_users5.O7_dictionary_accessibility =true restriction access to view or tables in other schema6.revoke system privilegesql> revoke create table from karen;sql> revoke create session from scott;7.grant object privilegesql> grant execute on dbms_pipe to public;sql> grant update(first_name,salary) on employee to karen with grant option;8.display object privilege : view => dba_tab_privs, dba_col_privs9.revoke object privilegesql> revoke execute on dbms_pipe from scott [cascade constraints];10.audit record view :=> sys.aud$11. protecting the audit trailsql> audit delete on sys.aud$ by access;12.statement auditingsql> audit user;13.privilege auditingsql> audit select any table by summit by access;14.schema object auditingsql> audit lock on summit.employee by access whenever successful;15.view audit option : view=>all_def_audit_opts,dba_stmt_audit_opts,dba_priv_audit_opts,dba_obj_audit_opts16.view audit result: view=>dba_audit_trail,dba_audit_exists,dba_audit_object,dba_audit_session,dba_audit_statement第十一章: manager role1.create rolessql> create role sales_clerk;sql> create role hr_clerk identified by bonus;sql> create role hr_manager identified externally;2.modify rolesql> alter role sales_clerk identified by commission; sql> alter role hr_clerk identified externally;sql> alter role hr_manager not identified;3.assigning rolessql> grant sales_clerk to scott;sql> grant hr_clerk to hr_manager;sql> grant hr_manager to scott with admin option;4.establish default rolesql> alter user scott default role hr_clerk,sales_clerk; sql> alter user scott default role all;sql> alter user scott default role all except hr_clerk; sql> alter user scott default role none;5.enable and disable rolessql> set role hr_clerk;sql> set role sales_clerk identified by commission; sql> set role all except sales_clerk;sql> set role none;6.remove role from usersql> revoke sales_clerk from scott;sql> revoke hr_manager from public;7.remove rolesql> drop role hr_manager;8.display role informationview: =>dba_roles,dba_role_privs,role_role_privs,dba_sys_privs,role_sys_privs,role_tab_privs,session_roles第十二章: BACKUP and RECOVERY1.v$sga,v$instance,v$process,v$bgprocess,v$database,v$datafile,v$sgasta t2. Rman need set dbwr_IO_slaves or backup_tape_IO_slaves andlarge_pool_size3. Monitoring Parallel Rollback> v$fast_start_servers , v$fast_start_transactions4.perform a closed database backup (noarchivelog)> shutdown immediate> cp files /backup/> startup5.restore to a different location> connect system/manager as sysdba> startup mount> alter database rename file '/disk1/../user.dbf'to'/disk2/../user.dbf';> alter database open;6.recover syntax--recover a mounted database>recover database;>recover datafile '/disk1/data/df2.dbf';>alter database recover database;--recover an opened database>recover tablespace user_data;>recover datafile 2;>alter database recover datafile 2;7.how to apply redo log files automatically>set autorecovery on>recover automatic datafile 4;plete recovery:--method 1(mounted databae)>copy c:\backup\user.dbf c:\oradata\user.dbf>startup mount>recover datafile 'c:\oradata\user.dbf;>alter database open;--method 2(opened database,initially opened,not system or rollback datafile)>copy c:\backup\user.dbf c:\oradata\user.dbf (alter tablespace offline)>recover datafile 'c:\oradata\user.dbf' or>recover tablespace user_data;>alter database datafile 'c:\oradata\user.dbf' online or>alter tablespace user_data online;--method 3(opened database,initially closed not system or rollback datafile)>startup mount>alter database datafile 'c:\oradata\user.dbf' offline;>alter database open>copy c:\backup\user.dbf d:\oradata\user.dbf>alter database rename file 'c:\oradata\user.dbf'to'd:\oradata\user.dbf'>recover datafile 'e:\oradata\user.dbf' or recover tablespace user_data; >alter tablespace user_data online;--method 4(loss of data file with no backup and have all archive log) >alter tablespace user_data offline immediate;>alter database create datafile 'd:\oradata\user.dbf'as'c:\oradata\user.dbf''>recover tablespace user_data;>alter tablespace user_data online9.perform an open database backup> alter tablespace user_data begin backup;> copy files /backup/> alter database datafile '/c:/../data.dbf' end backup;> alter system switch logfile;10.backup a control file> alter database backup controlfile to 'control1.bkp';> alter database backup controlfile to trace;11.recovery (noarchivelog mode)> shutdown abort> cp files> startup12.recovery of file in backup mode>alter database datafile 2 end backup;13.clearing redo log file>alter database clear unarchived logfile group 1;>alter database clear unarchived logfile group 1 unrecoverable datafile;14.redo log recovery>alter database add logfile group 3 'c:\oradata\redo03.log'size 1000k; >alter database drop logfile group 1;>alter database open;or >cp c:\oradata\redo02.log' c:\oradata\redo01.log>alter database clear logfile 'c:\oradata\log01.log';。
oracle语法大全

第一篇基本操作--解锁用户alter user 用户account unlock;--锁定用户alter user 用户account lock;alter user scott account unlock;--创建一个用户yc 密码为a create user 用户名identified by 密码;create user yc identified by a;--登录不成功,会缺少create session 权限,赋予权限的语法grant 权限名to 用户;grant create session to yc;--修改密码alter user 用户名identified by 新密码;alter user yc identified by b;--删除用户drop user yc ;--查询表空间select *from dba_tablespaces;--查询用户信息select *from dba_users;--创建表空间create tablespace ycspacedatafile 'E:\oracle\app\product\11.2.0\dbhome_1\oradata\ycspace.dbf'size 2mautoextend on next 2m maxsize 5moffline ;--创建临时表空间create temporary yctempspacetempfile 'E:\oracle\app\product\11.2.0\dbhome_1\oradata\ycspace.dbf'size 2mautoextend on next 2m maxsize 5moffline ;--查询数据文件select *from dba_data_files;--修改表空间--1、修改表空间的状态--默认情况下是online,只有在非离线情况下才可以进行修改alter tablespace ycspace offline ; --离线状态,不允许任何对象对该表空间的使用,使用情况:应用需要更新或维护的时候;数据库备份的时候alter tablespace ycspace read write;--读写状态alter tablespace ycspace online;alter tablespace ycspace read only; --只读,可以查询信息,可以删除表空间的对象,但是不能创建对象和修改对象。
oracle数据库常用的操作命令

问题提出:
1、用户需要对数据库用户下的每一张表都执行一个相同的SQL操作,这时,一遍、一遍的键入SQL语句是很麻烦的
实现方法:
SQL> set heading off --禁止输出列标题
SQL> set feedback off --禁止显示最后一行的计数反馈信息
alter user system indentified by test
~~~~~~~~~~~~~~~~~~~~~~``
Oracle 常用指令 SQL> show all --查看所有68个系统变量值
SQL> show user --显示当前连接用户
SQL> show error --显示错误
列出当前用户下所有同义词的定义,可用来测试同义词的真实存在性
select 'desc '||tname from tab where tabtype='SYNONYM';
查询当前用户下所有表的记录数
select 'select '''||tname||''',count(*) from '||tname||';' from tab where tabtype='TABLE';
(注:a后面跟2个空格)
(c)hange/old/new 在当前行用新的文本替换旧的文本 c/*/tname 结果:select tname from tab;
(c)hange/text 从当前行删除文本 c/tab 结果:select tname from ;
Oracle常用SQL命令

Oracle常⽤SQL命令创建表空间1.创建默认表空间WLP_DATCREATE TABLESPACE "MYSPACE" DATAFILE'D:\oracle\oradata\orcl\data/WLP_DAT.dbf' SIZE 32M REUSE AUTOEXTEND ON NEXT 32MLOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;2.创建临时表空间WLP_TEMP(⽤于缓存,可以不建)ALTER TABLESPACE "TEMP" ADD TEMPFILE'D:\oracle\oradata\orcl\data/WLP_TEMP.dbf' SIZE 32m REUSE autoextend on next 32m;创建⽤户并授权1CREATE USER "WLPING" PROFILE "DEFAULT"2 IDENTIFIED BY "123456"3DEFAULT TABLESPACE "MYSPACE" //默认指定表空间4TEMPORARY TABLESPACE "TEMP" //指定缓存表空间5 ACCOUNT UNLOCK; //⽤户⾮锁定67GRANT EXECUTE ON dbms_comparison TO "WLPING";8GRANT UNLIMITED TABLESPACE TO "XIR_MD";9GRANT "CONNECT" TO "XIR_MD";10GRANT "RESOURCE" TO "XIR_MD";1112-- GRANT DBA TO XIR_MD;PROFILE:Oracle系统中的profile可以⽤来对⽤户所能使⽤的数据库资源进⾏限制,使⽤Create Profile命令创建⼀个Profile,⽤它来实现对数据库资源的限制使⽤,如果把该profile分配给⽤户,则该⽤户所能使⽤的数据库资源都在该profile的限制之内。
常用oracle数据库命令

常用oracle数据库命令
1. 启动Oracle数据库
$ sqlplus /nolog
SQL> connect / as sysdba
SQL> startup
3. 创建表空间
创建表空间的命令是:
SQL> create tablespace 表空间名 datafile '路径名' size 大小;
6. 创建用户
7. 删除用户
删除用户的命令是:
8. 授权用户
SQL> grant 权限 to 用户名;
9. 撤销用户的权限
11. 查看表结构
查看表结构的命令是:
SQL> desc 表名;
SQL> create table 表名 (列名数据类型, 列名数据类型, …);
13. 删除表
14. 插入数据
插入数据的命令是:
SQL> update 表名 set 列名=新值 where 某条件;
18. 创建索引
20. 查看索引
21. 查询相关信息
查询相关信息的命令是:
SQL> select * from v$session; -- 查看会话 22. 查看数据库版本
24. 备份数据库
$ exp 用户名/密码 file=备份文件路径备注:以上命令均需要在Oracle登录后进行。
oracle查询实例命令

oracle查询实例命令以下是一些Oracle数据库中常用的查询实例命令示例:1.查询表的所有数据:SELECT * FROM table_name;2.查询指定列的数据:SELECT column1, column2, ... FROM table_name;3.查询满足特定条件的数据:SELECT * FROM table_name WHERE condition;4.对结果进行排序:SELECT * FROM table_name ORDER BY column_name [ASC|DESC];5.使用聚合函数进行数据统计:SELECT COUNT(*) FROM table_name; -- 统计行数SELECT SUM(column_name) FROM table_name; -- 求和SELECT AVG(column_name) FROM table_name; -- 平均值SELECT MAX(column_name) FROM table_name; -- 最大值SELECT MIN(column_name) FROM table_name; -- 最小值6.连接多个表进行查询:SELECT t1.column1, t2.column2 FROM table1 t1 JOIN table2 t2 ON t1.id = t2.id;7.使用条件进行分组:SELECT column1, COUNT(*) FROM table_name GROUP BY column1;8.使用LIKE进行模糊查询:SELECT * FROM table_name WHERE column_name LIKE 'keyword%';以上只是一些常见的查询示例,实际查询命令会根据具体的表结构和查询需求而有所不同。
在使用Oracle数据库时,请根据具体情况和需求构建和调整查询语句。
oracle数据库语句汇总
oracle数据库语句汇总在Oracle数据库中,有许多常用的SQL语句可以用于查询、插入、更新和删除数据。
下面列举了一些常见的Oracle数据库语句,以供参考。
1. 查询表中的所有数据:```SELECT * FROM 表名;```2. 查询表中的特定字段数据:```SELECT 字段1, 字段2, ... FROM 表名;```3. 查询表中满足特定条件的数据:```SELECT * FROM 表名 WHERE 条件;```4. 对查询结果进行排序:```SELECT * FROM 表名 ORDER BY 字段 ASC/DESC;```5. 对查询结果进行分组:```SELECT 字段1, 字段2, ... FROM 表名 GROUP BY 字段;```6. 对查询结果进行统计:```SELECT COUNT(*) FROM 表名;```7. 插入数据到表中:```INSERT INTO 表名(字段1, 字段2, ...) VALUES (值1, 值2, ...);```8. 更新表中的数据:```UPDATE 表名 SET 字段1 = 值1, 字段2 = 值2 WHERE 条件;9. 删除表中的数据:```DELETE FROM 表名 WHERE 条件;```10. 创建新表:```CREATE TABLE 表名 (字段1 数据类型,字段2 数据类型,...);```11. 修改表结构:```ALTER TABLE 表名 ADD (字段数据类型); ```12. 删除表:DROP TABLE 表名;```13. 创建索引:```CREATE INDEX 索引名 ON 表名 (字段);```14. 删除索引:```DROP INDEX 索引名;```15. 创建视图:```CREATE VIEW 视图名 AS SELECT * FROM 表名 WHERE 条件; ```16. 删除视图:```DROP VIEW 视图名;17. 创建存储过程:```CREATE PROCEDURE 存储过程名ISBEGIN-- 存储过程的具体逻辑END;```18. 调用存储过程:```EXEC 存储过程名;```以上是一些常见的Oracle数据库语句,可以满足大部分基本的数据操作需求。
oracle语法大全
第一篇基本操作--解锁用户alter user 用户account unlock;--锁定用户alter user 用户account lock;alter user scott account unlock;--创建一个用户yc 密码为a create user 用户名identified by 密码;create user yc identified by a;--登录不成功,会缺少create session 权限,赋予权限的语法grant 权限名to 用户;grant create session to yc;--修改密码alter user 用户名identified by 新密码;alter user yc identified by b;--删除用户drop user yc ;--查询表空间select *from dba_tablespaces;--查询用户信息select *from dba_users;--创建表空间create tablespace ycspacedatafile 'E:\oracle\app\product\11.2.0\dbhome_1\oradata\ycspace.dbf'size 2mautoextend on next 2m maxsize 5moffline ;--创建临时表空间create temporary yctempspacetempfile 'E:\oracle\app\product\11.2.0\dbhome_1\oradata\ycspace.dbf'size 2mautoextend on next 2m maxsize 5moffline ;--查询数据文件select *from dba_data_files;--修改表空间--1、修改表空间的状态--默认情况下是online,只有在非离线情况下才可以进行修改alter tablespace ycspace offline ; --离线状态,不允许任何对象对该表空间的使用,使用情况:应用需要更新或维护的时候;数据库备份的时候alter tablespace ycspace read write;--读写状态alter tablespace ycspace online;alter tablespace ycspace read only; --只读,可以查询信息,可以删除表空间的对象,但是不能创建对象和修改对象。
Oracle常用命令大全(很有用,做笔记)
Oracle常⽤命令⼤全(很有⽤,做笔记)⼀、ORACLE的启动和关闭1、在单机环境下要想启动或关闭ORACLE系统必须⾸先切换到ORACLE⽤户,如下su - oraclea、启动ORACLE系统oracle>svrmgrlSVRMGR>connect internalSVRMGR>startupSVRMGR>quitb、关闭ORACLE系统oracle>svrmgrlSVRMGR>connect internalSVRMGR>shutdownSVRMGR>quit启动oracle9i数据库命令:$ sqlplus /nologSQL*Plus: Release 9.2.0.1.0 - Production on Fri Oct 31 13:53:53 2003Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.SQL> connect / as sysdbaConnected to an idle instance.SQL> startup^CSQL> startupORACLE instance started.2、在双机环境下要想启动或关闭ORACLE系统必须⾸先切换到root⽤户,如下su - roota、启动ORACLE系统hareg -y oracleb、关闭ORACLE系统hareg -n oracleOracle数据库有哪⼏种启动⽅式说明:有以下⼏种启动⽅式:1、startup nomount⾮安装启动,这种⽅式启动下可执⾏:重建控制⽂件、重建数据库读取init.ora⽂件,启动instance,即启动SGA和后台进程,这种启动只需要init.ora⽂件。
2、startup mount dbname安装启动,这种⽅式启动下可执⾏:数据库⽇志归档、数据库介质恢复、使数据⽂件联机或脱机,重新定位数据⽂件、重做⽇志⽂件。
Oracle数据库语句大全
Oracle数据库语句大全一.入门部分1.创建表空间create tablespace schooltbs datafile ‘D:\oracle\datasource\schooltbs.dbf’ size 10M autoextend on;2.删除表空间drop tablespace schooltbs[including contents and datafiles];3.查询表空间基本信息select *||tablespace_name from DBA_TABLESPACES;4.创建用户create user lihuaidentified by lihuadefault tablespace schooltbstemporary tablespace temp;5.更改用户alter user lihuaidentified by 123default tablespace users;6.锁定用户alter user lihua account lock|unlock;7.删除用户drop user lihua cascade;--删除用户模式8.oracle数据库中的角色connect,dba,select_catalog_role,delete_catalog_role,execute_catalo g_role,exp_full_database,imp_full_database,resource9.授予连接服务器的角色grant connect to lihua;10.授予使用表空间的角色grant resource to lihua with grant option;--该用户也有授权的权限11.授予操作表的权限grant select,insert on user_tbl to scott;--当前用户grant delete,update on er_tbl to scott;--系统管理员二.SQL查询和SQL函数1.SQl支持的命令:数据定义语言(DDL):create,alter,drop数据操纵语言(DML):insert,delete,update,select数据控制语言(DCL):grant,revoke事务控制语言(TCL):commit,savepoint,rollback2.Oracle数据类型字符,数值,日期,RAW,LOB字符型char:1-2000字节的定长字符varchar2:1-4000字节的变长字符long:2GB的变长字符注意:一个表中最多可有一列为long型Long列不能定义唯一约束或主键约束long列上不能创建索引过程或存储过程不能接受long类型的参数。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1.查询数据库状态 select status from v$instance;查看数据库版本 select * from v$version;more /home/oracle/.bash_profile 查看数据库的运行环境listener.ora和tnsnames.ora:放在“/ORACLE_HOME/network/admin”子目录下,是SQL*Net V2正常工作所需的配置文件及整个网络的配置文件。
listener.ora是服务器监听进程网络配置文件,tnsnames.ora 是客户机与服务器联络所需的网络配置文件。
2、创建一个表空间,数据文件创建在/export/home/自己名字的目录,数据文件100MCREATE TABLESPACE test LOGGING DATAFILE ‘d:\dev\test.dbf' SIZE 100M;CREATE TEMPORARY TABLESPACE test_tmp tempfile '/export/home/test_tmp.dbf' SIZE 100M;3、创建用户,表空间使用自己创建的表空间。
create user test identified by test default tablespace test profile default;grant create session,create table to test;grant create view to test;grant create sequence to test;grant UNLIMITED TABLESPACE to test;commit;4、连接到自己创建的用户上Sql>Connect user/password5、创建表CREATE TABLE EMP(EMPNO NUMBER(4) NOT NULL,ENAME VARCHAR2(10),JOB VARCHAR2(9),MGR NUMBER(4),HIREDATE DATE,SAL NUMBER(7, 2),COMM NUMBER(7, 2),DEPTNO NUMBER(2));5、在表中插入数据INSERT INTO EMP VALUES(7369, 'SMITH', 'CLERK', 7902,TO_DATE('17-12-1980', 'DD-MM-YYYY'), 800, NULL, 20);INSERT INTO EMP VALUES(7499, 'ALLEN', 'SALESMAN', 7698,TO_DATE('20-02-1981', 'DD-MM-YYYY'), 1600, 300, 30);INSERT INTO EMP VALUES(7521, 'WARD', 'SALESMAN', 7698,TO_DATE('22-02-1981', 'DD-MM-YYYY'), 1250, 500, 30);INSERT INTO EMP VALUES(7566, 'JONES', 'MANAGER', 7839,TO_DATE('02-04-1981', 'DD-MM-YYYY'), 2975, NULL, 20);INSERT INTO EMP VALUES(7654, 'MARTIN', 'SALESMAN', 7698,TO_DATE('28-09-1981', 'DD-MM-YYYY'), 1250, 1400, 30);6、修改表中数据update7、删除表中一条数据delete from8、查找表中一条数据 select9、删除表 drop table10、删除用户 drop user test cascade;11、删除表空间 drop tablespace test including contents and datafiles;1)创建表空间drop tablespace smsc_center including contents;create tablespace smsc_center datafile '/dev/rlv_dbsmsc1' size 2000M reuse;alter tablespace smsc_center add datafile '/dev/rlv_dbsmsc2' size 2000M reuse;(动态扩充表空间)2、建立用户drop user smsc cascade;create user smsc identified by oracle default tablespace smsc_center profile default; grant dba to smsc;grant unlimited tablespace to smsc;commit;3、连接刚建立的用户上,创建表(sm_histable0101、ms_usertable)SQL>connect smsc/oracleSQL>create table ms_usertable(MSISDN varchar2(21) NOT NULL ,SubName varchar2(21) NULL ,UserSex number(3) NULL ,UserAddr varchar2(41) NULL ,UserPass varchar2(9) NULL ,MSType number(3) NULL ,TON number(3) NULL ,NPI number(3) NULL ,Service number(3) NULL ,SMFlag number(3) NULL ,OCOS number(10) NULL ,TCOS number(10) NULL ,ExpireTime number(10) NULL,RegDateTime varchar2(21) NULL,Schedulemode number(3) NULL)TABLESPACE SMSC_CENTER;4、建立存储过程 process5、建立任务 job补充:1、错误码解释 ora-15241 $oerr ora 15421tns-12542 $oerr tns 12542imp-00013 $oerr imp 000132、倒表命令exp smsc/oracle tables=sm_histable0426 file=sm_histable0426 log=sm_histable0426imp smsc/oracle file=sm_histable0426 log=sm_histable0426 tables=sm_histable0426 ignore=y3、保存查询结果SQL> spool /home/oracle/text.txtSQL>select * from V$tablespace;SQL> spool off4、建立、删除裸设备mklv -y 'lv92_system' -t 'raw' datavg 256 [256*8(pp size)=2048]rmlv -f 'lv92_system'5、命令select orgaddr,destaddr from sm_histable0920 where error_code='48';查询0920从源地址到目的地址错误码为48的数据select * from sm_histable1228 where destaddr like'8613%' and orgaddr like'8613'%;count(*) 查询1228从源地址8613发往目的地址8613的所有数据analyze table sm_histable1228 compute statistics for all indexes (优化表索引)truncate table sm_histable1228; 清除表中所有数据,保留表结构,不可恢复数据delete from sm_histable1228; 没有commit前可以,用rollback命令回滚。
desc ms_usertable 查看表结构select status from gv$instance; 查询实例是否启动select * from all_users; 查询系统拥有哪些用户select * from tab; 查询当前用户下的所有对象show user 查询当前连接用户show sgaselect * from dual;select * from V$NLS_PARAMETERS; 查询字符集相关seletc * from V$tablespace; 查询所有的表空间select userenv('language') from dual;SQL>create table test(id number(3));SQL>insert into test values (1);SQL>insert into test values (2);SQL>commitSQL>delete from test where id=1;SQL>rolback 没有commit前可以,用rollback命令回滚。
update ms_usertable set ocos='100' tcos='200' where ... ; 要表中有数据才可以删除表 drop table删除用户 drop user test cascade;删除表空间 drop tablespace test including contents and datafiles;select username,count(*) from v$session group by username假设表a中有100条记录,b为表a中的一个字段.那么查询显示表a中按字段b排序的91-100条记录语句该怎么写?查旬81-90条的记录语句怎么写?查找m-n条记录的语句又怎么写呢(m<n且1<m<100,1<n<100)?请各位高手指教!!!SELECT ROWNUM,其它字段FROM (SELECT * FROM a ORDER BY b )WHERE ROWNUM >=m AND ROWNUM <= n;==============================================================================一、ORACLE的启动和关闭1、在单机环境下要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下su - oraclea、启动ORACLE系统oracle>svrmgrlSVRMGR>connect internalSVRMGR>startupSVRMGR>quitb、关闭ORACLE系统oracle>svrmgrlSVRMGR>connect internalSVRMGR>shutdownSVRMGR>quit启动oracle9i数据库命令:$ sqlplus /nologSQL*Plus: Release 9.2.0.1.0 - Production on Fri Oct 31 13:53:53 2003Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.SQL> connect / as sysdbaConnected to an idle instance.SQL> startup^CSQL> startupORACLE instance started.2、在双机环境下要想启动或关闭ORACLE系统必须首先切换到root用户,如下su - roota、启动ORACLE系统hareg -y oracleb、关闭ORACLE系统hareg -n oracleOracle数据库有哪几种启动方式说明:有以下几种启动方式:1、startup nomount非安装启动,这种方式启动下可执行:重建控制文件、重建数据库读取init.ora文件,启动instance,即启动SGA和后台进程,这种启动只需要init.ora文件。