oracle10g 的基本操作

 
表空间的管理

1、创建表空间
SQL> select * from dba_free_space;  // 查询表空间是否存在碎片

1、创建表空间
(1)语法:SQL> Create Tablespace tablespacename
   Datafile 'filespec' Attributes
   Default Storage
   permanent/temporary
   logging/nologging
   Online/offline;

(2)实例:SQL> create tablespace ts1 datafile
  2  'D:/oracle/product/10.2.0/oradata/mstdb/test_db01.dbf' size 100m
  3  autoextend on next 100m maxsize 1024m
  4  default storage (initial 10m next 1m)
  5  permanent
  6  online
  7  logging;
备注:如果权限不够,则改用sysdba权限:
SQL> conn sys/*** as sysdba

在表空间创建表,不指定空间一般在默然空间user中
SQL> create table userinfo1
  2   (userid varchar2(20),
  3   username varchar2(30))
  4  tablespace ts1;

2、删除表空间

SQL> drop tablespace ts1;--删除不了数据文件

SQL> drop tablespace ts1 including contents and datafiles;--删除数据文件



表的管理

1、创建表

SQL> create table test
  2  (testid varchar2(20),
  3  testname varchar2(30));

2、修改表

2.1、修改字段类型

SQL> alter table test
  2  modify  (testname varchar2(25));

2.2、添加一个字段

SQL> alter table test
  2  add (testdate  date);

3、查看表结构

SQL> describe test;

4、删除表

SQL> drop table test;

5、表的重命名

SQL> rename test to retest;

6、截段表

SQL> truncate table test;

7、添加表的注释

SQL> comment on table test is 'this is test table';

8、查看表的注释

SQL> select * from all_tab_comments;

9、查询用户拥有表的说明

SQL> select * from user_tables;

10、查询用户拥有的不同对象

SQL> select * from user_objects;

11、查询用户拥有的表、视图

SQL> select * from user_catalog;



数据的操作与管理

1、插入数据

SQL>  insert into test(testid,testname,testdate)
  2  values('1','test',sysdate);

2、删除数据

SQL> delete from test;

3、使用代替变量(&)和to_date函数

SQL>  insert into test(testid,testname,testdate)
  2   values(&testid,'iframe',to_date('06-02-12','yyyy-mm-dd'));

SQL> insert into test(testid,testname,testdate)
  2  values(&testid,'iframe',to_timestamp('2006-07-23 12:45:12:12','yyyy-mm-dd hh24:mi:ss:ff'));

附加:日期函数
日期格式构成方法:

  年   月   日   时    分  秒
  yy    mm   dd   hh(12小时制)  mi  ss
  yyyy   mon   dy(星期)  hh24(24小时制)
     month  day  
 
A. yy.mm.dd, yy/mm/dd, yy-mm-dd, yyyy.mm.dd, ... 加中文也可以,中文要用又引号括起来

SQL>select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') from test;  // test是一个虚拟表,任何用户都可以使用。

日期格式参数 含义说明
D 一周中的星期几
DAY 天的名字,使用空格填充到 9 个字符
DD 月中的第几天
DDD 年中的第几天
DY 天的简写名
IW ISO 标准的年中的第几周
IYYY ISO 标准的四位年份
YYYY 四位年份
YYY,YY,Y 年份的最后三位,两位,一位
HH 小时,按 12 小时计
HH24 小时,按 24 小时计
MI 分
SS 秒
MM 月
Mon 月份的简写
Month 月份的全名
W 该月的第几个星期
WW 年中的第几个星期

4、修改表数据

SQL> update test set testname='aksdfljsd' where testid='1';

5、数据库的事务

commit;
rollback;
savepoint firstdata;

用户与权限管理

1、创建用户


SQL> create user u01
  2  identified by user01;

2、修改用户密码

SQL> alter user u01
  2   identified by u01;

3、授权用户

SQL> grant create session to u01;

附加:
create session    连接到数据库
create table      创建表
create sequence   创建序列
create view       创建视图
create proceduer  创建程序

4、撤消授权

SQL> revoke create table from u01;




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值