oracle常用命令入门

登录oracle(需要在oracle用户下)

执行sqlplus,然后输入用户名和密码就可以了,如果是第一次使用oracle的话,可以直接使用sqlplus / as sysdba免密码以管理员的身份登录

开启或关闭数据库

进入sqlplus命令行之后,执行startup启动oracle,执行shutdown immediate关闭oracle

查看当前数据库状态

select status from v$instance;

创建第一个自定义用户test

create user test identified by 123456; 创建一个用户名为test,密码为123456的用户

给这个用户授权

grant dba to test;   使test用户拥有dba管理员权限,其中权限还有connect和resource

删除test用户

drop user test;

修改test密码

alter user test identified by 666;

查看某用户信息

select username,account_status from dba_users where username='scott';

现在我们尝试远程使用test用户登录oracle服务器

sqlplus test/123456@//172.16.1.99:1521/orcl  因为oracle的默认端口是1521,orcl是我创建的数据库名

现在我想看一下数据库名称

select name from v$database;

查看时间,select sysdate from dual;

自带的时间格式看不懂,可以进行转换为我们常见的格式

alter session set nls_date_format="yyyy-mm-dd";

查看scott用户test表十分钟前的数据

select * from scott.test as of timestamp sysdate-10/1440;     1440是一天的分钟数24*60

 查看ORACLE 数据库中本用户下的所有表 
SELECT table_name FROM user_tables;

 

插入一条数据,注意列名num需要有引号括起来,否则会报错,oracle的列名最好都用引号括起来,否则会报ORA-00904错误,invalid identifier

insert into "company" ("num") values(99);    

更新一条信息,注意,如果oracle和mysql不同,如果是两个条件,不实用and,而是使用逗号分隔,否则会报错

update "company" set "num"=666 where "num"=6;

update "company" set "num"=666,"id"=2 where "num"=6; (oracle)

update "company" set "num"=666 and "id"=2 where "num"=6; (mysql)

删除一条信息

delete from "company" where "num"=9;

查看当前用户表结构

select * from user_tab_columns;

查看表注释

select * from user_tab_comments;

跨用户对数据库表进行授权,将a用户的table1表授权给用户b。注意:需要使用管理员权限运行

grant select,insert,update,delete on a.table1 to b;

 穿件数据库表空间

create tablespace JCK_DATA  datafile 'E:/app/Administrator/oradata/orcl/jck_data01.dbf' size 2G;

原文地址:https://www.cnblogs.com/biaopei/p/8065940.html