数oracle的并语法,oracle基本语法

本文介绍了如何在Oracle数据库中创建和管理表空间,包括创建表空间、删除表空间、查询表空间信息、为表空间添加数据文件、创建和删除用户、授权与撤销权限、操作表结构以及查询系统信息。此外,还涉及到了表空间的使用率查询、调整Oracle连接数以及主键和外键的概念。
摘要由CSDN通过智能技术生成

1,创建表空间,表空间名字为database,目录为datafile ‘d:\oracle\product\10.2.0\oradata\data01.dbf‘ ,大小为100M,每次自动扩展10M,最大无限制。

create tablespace  database datafile ‘d:\oracle\product\10.2.0\oradata\data01.dbf‘ size 100M autoextend on next 10M maxsize unlimited;

2,删除表空间database

drop tablespace database;

3,查询表空间

select * from dba_data_files;

4,给表空间增加数据文件。

alter tablespace database add datafile ‘d:\oracle\product\10.2.0\oradata\data02.dbf‘ size 100m autoextend on 10M maxsize unlimited;

5,创建用户并指定默认表空间

create user wyy identified by wyy default tablespace database;

6,查询所有用户

select * from all_users;

7,删除用户

drop user wyy  cascade;

8,删除表空间

drop tablespace database including contents and datafiles cascade constraints;

注: including contents and datafiles删除表空间的内容、数据文件

cascade constraints删除表空间的参照外键

8,给用户授权

grant connect,resource to wyy

去除权限

revoke connect,resource from wyy

9,查询当前用户的权限

select * from user_role_privs;

10,查询用户的所有表

select * from user_tables;

11,创建一个学生student表,表中含两列

create table student (xh varchar2(10), xm varchar2(10))

12,向表中增加一列xb

alter table student add (xb varchar2(4))

13,  给表增加注释

comment on column student.xh is ‘学号‘

14,查询数据库sid

select name from V$database

15,更改表的一列字段长度

a,若没数据

alter table student modify xh varchar2(20)

b,若有数据,新建一个列,更新数据到新列,然后删除原列,然后改变列名

alter table student add xh_temp varchar2(20);

update student set xh_temp=xh;

commit;

alter table student drop xh;

alter table student rename xh_temp=xh;

16.

选择:select * from table1 where 范围

插入:insert into table1(field1,field2) values(value1,value2)

insert into table1 values(value1,value2,value3,value4)

删除:delete from table1 where 范围

更新:update table1 set field1=value1 where 范围

17,查询表空间的使用率

SELECT a.tablespace_name 表空间名,

total 表空间大小,

free 表空间剩余大小,

(total - free) 表空间使用大小,

ROUND((total - free) / total, 4) * 100 使用率

FROM (SELECT tablespace_name, ROUND(SUM(bytes) / (1024 * 1024), 4) free

FROM DBA_FREE_SPACE

GROUP BY tablespace_name) a,

(SELECT tablespace_name, ROUND(SUM(bytes) / (1024 * 1024), 4) total

FROM DBA_DATA_FILES

GROUP BY tablespace_name) b

WHERE a.tablespace_name = b.tablespace_name;

18,修改Oracle连接数

查看ORACLE最大进程数:

SQL> show parameter processes #最大连接

SQL> alter system set processes = value scope = spfile; #修改连接

重启数据库,使连接数生效。

19.主键与外键

主键(Primary Key):用来唯一标识表中一行的候选键,一个表只能有一个主键。

外键(Foreign Key):一个表的字段,是另外一个表的主键。

20,从一个表向另一个表复制

insert into 表2(column1,column2,column3) select column1,column2,column3 from 表1

21,创建索引

create index 索引名字 on student(xh,name,bj);

22,降序升序

select * from xs_xjb order by xh asc    升序

select * from xs_xjb order by xh desc  降序

23,查询系统当前时间

select sysdate from dual

24,更改系统大小写

update table set sfzh = upper(‘sfzh‘)

25,Oracle密码超过时间限制

select * from dba_profile;

alter profile default limit FAILED_LOGIN_ATTEMPTS unlimited;

alter profile default limit PASSWORD_LIFE_TIME unlimited;

原文:http://www.cnblogs.com/wu1314421/p/4468974.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值