加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle

发布时间:2020-12-12 13:45:05 所属栏目:百科 来源:网络整理
导读:create table t_class( tc_id? number(5) not null, tc_name varchar2(30) not null, createdate date ) create table t_user( t_id? number(5) not null, t_name varchar2(30) not null, tc_id number(5) ) 将orcle一些使用总结了一下 1.日期: 添加日期字

create table t_class(

  tc_id? number(5) not null,

  tc_name varchar2(30) not null,

  createdate date  

)

create table t_user(

  t_id? number(5) not null,

  t_name varchar2(30) not null,

  tc_id number(5)

)

将orcle一些使用总结了一下

1.日期:

  添加日期字段:  alert table t_class add(learndate? date);

  修改字段:    alert table t_class modify(column1 number not null )? -- modify? 修改数据类型,以及是否为空? column1 列名

           alert table t_class rename column filed_name to new_filed_name; ? --rename 修改字段名

  删除字段:    alert table t_class drop(column)

  插入日期格式数据:? to_date()函数

    insert into t_class values(1001,‘class1‘,to_date(‘2018-9-28‘,‘yyyy-mm-dd‘));

    insert into t_class values(1002,‘class2‘,‘yyyy-mm-dd‘));

  显示正常年月日的日期:

    select to_char(createdate,‘yyyy-mm-dd‘) from t_class;

2.查询区间数据

  前10行数据,加别名

    select tc_id? 班级号,tc_name 班级名,createdate 班级创建时间 from t_class? where rownum<=10;

  3-5条数据

    select tc_id,tc_name from ( select? tc.*,rownum as rowno from t_class tc )? where rowno between 3 and 5;

3.利用旧表创建新表,不要数据

  create table t_base

  as

  select * from t_class where 1=2;

?

==================================================

创建用户,表空间,角色,授予用户角色权限

1.以系统管理员身份登录 sql plus

  conn scott/tiger as sysdba;  --scott用户以sysdba的身份登录

2.创建新用户,修改新用户密码

  create user zhangfei? identified by zf123;?? --注意用户不要为关键字

  alter user zhangfei? identified by zff123;

3.给该用户分配一个表空间

  create tablespace ts_zf? datafile? ‘f:tt_ppkk.dbf‘ size? 200M;   --datafile 后面是表空间的物理存储路径,文件的后缀名随意

  alter user zhangfei? default? tablespace? ts_zf;

4.分配空间后暂时还不能登录,没有登录权限,需分配权限

  grant? create table,create session,create view,create sequence,unlimited? tablespace? to zhangfei;? --session是登录数据库权限

  conn zhangfei/zff123;    --可以登录数据库

5.简化版授予权限,由于自带三张标准角色,所以可以直接通过角色授予使得用户可以登录数据库并可以操作表,序列,过程,触发器,索引,簇

  grant connect,resource to zhangfei;

?????? revoke? connect,resource from zhangfei ;    --撤销权限  

6.创建角色

  create role? rolename;

7.授予角色

  grant select on class to 角色名 ;? 授予用户操作class表对象的权限,允许用户查询class表

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读