zoukankan      html  css  js  c++  java
  • Oracle使用

    1.创建表空间
    #使用sys登录成功
    格式: create tablespace 表间名 datafile ‘数据文件名’ size 表空间大小;
    例如: create tablespace mytable datafile
    'd:myoraclemytables1.dbf' size 1024M segment space management auto; 若表空间在导入数据时不足时,可以修改表空间如下: SQL>alter database datafile 'd:myoraclemytables1.dbf' autoextend on; 删除命名空间 SQL>DROP TABLESPACE tablespace INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS;

    2.创建用户

    其格式为:格式: create user 用户 名 identified by 密码 default tablespace 表空间表;
    
    如:   
    
    SQL> create user ITMS identified by 123456 default tablespace mytable;
    
    默认表空间’default tablespace’使用上面创建的表空间。
    
    接着授权给新建的用户:
    
    SQL> grant connect,resource to ITMS; –表示把 connect,resource权限授予ITMS用户
    
    SQL> grant dba to ITMS; –表示把 dba权限授予给ITMS用户   授权成功。

    3.创建表

    #首先连接到对应的用户下,如果已经是对应的用户则忽略
    conn gary/gary as sysdba;
    
    #创建表
    create table s1(id int not null,name varchar(8) not null,tel int not null);

     4.修改表

    #修改表名
    rename s1 to tb1;
    #增加字段
    alter table tb1 add sex varchar(4);
    #修改字段名
    alter table tb1 rename column tel to tell;
    #删除字段
    alter table tb1 drop column sex;
    #修改字段类型
    alter table tb1 modify sex int;

    5.插入数据

    #插入数据
    insert into s1(id,name,tel) values ('1','xy','563628832');

     6.更新数据

    #更新数据
     update s1 set tel = '18317992874' where id = '1';

    7.删除表

    #删除表中的所有数据,速度比delete快很多,截断表
    truncate table 表名 
    
    delete from table 条件
    
    drop table 表名

    8.删除用户

    #删除用户
    drop user gary;
    
    #若用户拥有对象,无法直接删除用户,需要先删除用户所有对象再删除用户
    drop user gary cascade;
    drop user gary;

    9.查看当前所用数据库

    select instance_name from  V$instance;

     10.查看当前用户表

    #(user_tables是单用户级别,all_tables所有用户级别,dba_tables全局级别包括系统表)

    select table_name from user_tables;

    11.查看表结构

    #desc tb1;

    12.查看当前登录的用户

    select user from dual;
    
    show user;

    13.查看当前环境是pdb还是cdb(12c用11g用不到)

    select name,cdb,open_mode,con_id from v$database; 

    14. 查看oracle版本号

    select * from v$version;
  • 相关阅读:
    如何计算二进制数的取值范围
    理解网络请求中的连接超时和读取超时
    两行代码玩转Spring Data排序和分页
    面试必问Elasticsearch倒排索引原理
    你知道Java的四种引用类型吗
    抛弃配置后的Spring终极教程
    Python学习第二篇
    Python
    关于always块内for循环的执行方式
    三态门实现“一读多写”总线结构
  • 原文地址:https://www.cnblogs.com/xiongying4/p/14817110.html
Copyright © 2011-2022 走看看