Oracle常用的命令如何查看表的结构

数据库 Oracle
本文主要介绍的是Oracle常用的命令中如何查看表的结构,以下的文章提供了Oracle常用中十几个的相关的命令,望你会有所收获。

以下的文章主要是介绍Oracle常用的命令中如何查看表的结构,如果你对Oracle常用的命令中如何查看表的结构的这一实际操作方案感兴趣的话,你就可以浏览以下的文章对其有一个更好的了解。

EDITDATA 表名;

修改表字段:

Alter table 表名 modify(字段名 类型 约束);

 

  1. alter table test modify (addd varchar2(10) null); 

alter table 表名 add(字段名 类型 约束);

 

  1. alter table test add(age varchar2(5)); 

 

1.登陆系统用户

在Oracle常用命令中查看表结构sqlplus 然后输入系统用户名和密码

登陆别的用户

conn 用户名/密码;

2.创建表空间

 

  1. create tablespace 空间名  
  2. datafile 'c:\空间名' size 15M --表空间的存放路径,初始值为15M  
  3. autoExtend on next 10M --空间的自动增长的值是10M  
  4. permanent online; --***使用  

 

3.创建用户

 

  1. create user shi --创建用户名为shi  
  2. identified by scj --创建密码为scj  
  3. default tablespace 表空间名 --默认表空间名  
  4. temporary tablespace temp --临时表空间为temp  
  5. profile default --受profile文件的限制  
  6. quota unlimited on 表空间名; --在表空间下面建表不受限制  

 

4.创建角色

create role 角色名 identified by 密码;

5.给角色授权

grant create session to 角色名;--给角色授予创建会话的权限

grant 角色名 to 用户名; --把角色授予用户

6.给用户授予权限

 

  1. grant connect,resource to shi;--给shi用户授予所有权限  
  2. Grant dba to shi;-给shi 用户授予DBA权限  
  3. grant create table to shi; --给shi用户授予创建表的权限  

 

7.select table_name from user_tables;   察看当前用户下的所有表

8.select tablespace_name from user_tablespaces; 察看当前用户下的 表空间

9.select username from dba_users;察看所有用户名称命令 必须用sys as sysdba登陆

10.创建表

create table 表名

 

  1. (  
  2. id int not null,  
  3. name varchar2(20) not null  
  4. )tablespace 表空间名 --所属的表空间  
  5. storage  
  6. (  
  7. initial 64K --表的初始值  
  8. minextents 1 --最小扩展值  
  9. maxextents unlimited --***扩展值  
  10. );  

 

11.为usrs表添加主键和索引

 

  1. alter table users  
  2. add constraint pk primary key (ID);  

 

12.为已经创建users表添加外键

 

  1. alter table users  
  2. add constraint fk_roleid foreign key (roleid)  
  3. references role(role_id) on delete cascad; --下边写主表的列  
  4. on delete cascad是创建级联  

 

13.把两个列连接起来

  1. select concat(name,id) from 

表名; --把name和id连接起来

14.截取字符串

  1. select column(name,'李') from 

表名;把name中的‘李’去掉

15.运行事务之前必须写

  1. set serveroutput on;  

打开输入输出(不写的话,打印不出信息)

16.while的应用

 

  1. declare --声明部分  
  2. ccc number:=1; --复职  
  3. number:=0;  
  4. begin --事务的开始  
  5. while ccc<=100 loop --循环  
  6. if((ccc mod 3)=0) then --条件  
  7. dbms_output.put_line(ccc||',');    --打印显示  
  8. aa:=a+ccc;  
  9. end if; --结束if  
  10. cc:=ccc+1;  
  11. end loop; --结束循环  
  12. dbms_output.put_line(a);  
  13. end; --结束事务  

 

17.select into 的用法 --只能处理一行结果集

 

  1. declare  
  2. name varchar(30);  
  3. begin  
  4. select username into name  
  5. from users  
  6. where id=2;  
  7. dbms_output.put_line('姓名为:'||name);  
  8. end;  
  9. /  

上述的相关内容就是对Oracle常用命令中查看表结构的描述,希望会给你带来一些帮助在此方面。

【编辑推荐】

  1. Oracle透明网关的内容介绍
  2. Oracle如何复制表的sql语句
  3. x86渐热 Oracle数据库服务器选型指南
  4. Oracle web环境注射技术在真实世界里注射
  5. Oracle Web Hacking 基本思路的描述
责任编辑:佚名 来源: 博客园
相关推荐

2010-05-26 16:29:51

MySQL查看

2010-05-12 14:26:01

MySQL查看表结构

2010-10-27 16:33:39

Oracle查看表空间

2010-04-16 10:00:06

Oracle查看表空间

2010-10-15 10:29:25

Mysql表结构

2010-04-12 14:22:13

Oracle性能sql语句

2010-04-07 11:21:28

Oracle常用命令

2010-04-12 13:25:10

Oracle 数据库

2010-04-13 13:01:21

Oracle exp

2010-04-19 09:37:22

Oracle查询语句

2014-08-13 09:29:15

linux

2020-12-04 10:40:32

Oracle运维命令

2010-04-07 16:21:11

Oracle常用命令

2021-06-10 16:18:39

Oracle账号信息

2017-10-16 18:29:36

数据库Oracle常用语句

2010-04-06 09:20:58

Oracle job

2021-01-20 13:50:45

MySQL数据库代码

2011-03-16 14:38:55

iptables命令

2010-04-02 17:37:15

Oracle rman

2010-04-26 18:32:48

Oracle数据库
点赞
收藏

51CTO技术栈公众号