orcale 数据库语句(一)
创建表空间、用户、分配角色
先运用管理员身份登录orcale数据库
创建表空间
create tablespace empt_tablespace datafile 'D:\epet.dbf' size 100m;
运行后如图
创建用户
create user aaa identified by 123 default tablespace empt_tablespace;
运行后如图,用户名为aaa,密码123.
分配角色,分配的角色为管理员
grant dba to aaa;
完成以上操作后,用自己的aaa用户进行登录
创建表格
首先创建用户表(包含ID、用户名、密码及用户状态)
create table userInfo(
id number(10) primary key,
name nvarchar2(20) not null,
password nvarchar2(20) not null,
status varchar(10) default 1
)
增加表内列(电话)
alter table userInfo add phone number(12);
修改列属性(此时不需要)
alter table userInfo modify phone char(12);
删除一列`(用来演示,先随便添加一列,这样删除这列不影响表)
alter table userinfo add 11 char(11);
alter table userinfo drop column 11;`
创建序列
create sequence user_seq start with 1 increment by 1;
创建好表和序列如图所示
select user_seq.nextval from dual;--下一个值
select user_seq.currval from dual;--当前值
数据处理
添加数据
insert into userInfo values(1,'aa','1','1',124343234);
insert into userInfo values(2,'bb','13','0',1243);
insert into userInfo values(3,'cc','321','1',1234);
insert into userInfo values(4,'dd','213r','0',124434);
insert into userInfo values(5,'ee','2q3r','2',234);
insert into userInfo values(6,'qq','weqr','1',14);
insert into userInfo values(7,'ww','234','2',3234);
insert into userInfo(id,name,password) values(user_seq.nextval,'next','222');
--利用序列可以自动添加ID
删除数据
delete from userinfo where id=5;--要用where设置条件
修改数据
update userinfo set name='newName' where id=4;
update userinfo set phone=null;
查询数据(关键点)
select * from userinfo;--查询全部数据
select name,password from userinfo; --查询部分列的数据
select * from userinfo where status=1;--where可以添加查询条件
select * from userinfo where status=1 and id>3;--并列的条件用and
select * from userinfo where status=1 or id>3;--或的条件用or
select * from userinfo where status=1 and id>3 or name='cc';--and与or一起使用,and的优先级高
select * from userinfo where (name='cc' or status=1) and not id>3;
--先()然后not 接着and 最后or(优先级)select userinfo.name,userinfo.password from userinfo;--查询部分数据
select u.name as n,u.password as p from userinfo u;--修改名字(简写用)
select u.name n ,u.password p from userinfo u;--查询部分数据
模糊查询
select * from userinfo where name like '%a';--查询以a开头 a%以a结尾 %a%中间包含a
空值查询、非空值查询
select * from userinfo where phone is null;--空值查询select * from userinfo where phone is not null;--不是空值得查询
排序
select * from userinfo order by id;--默认是升序
select * from userinfo order by id asc;--升序
select * from userinfo where id>0 order by id desc;--降序
范围查询
select * from userinfo where id>=2 and id<=4;select * from userinfo where id between 2 and 4;--二到四之间
组成员查询
select * from userinfo where id=1 or id=2 or id=4;select * from userinfo where id in(1,2,4);--in可取到集合里的值和上面结果一致select * from (select u.*,rownum rn from (select * from userinfo order by id) u ) where rn>3 and rn<7;--引入了行,一页只显示3个select * from (select u.*,rownum rn from (select * from userinfo order by id) u where rownum<7 ) where rn>3;--优化版
小结检测
按id从大到小 取前三行
答案:
select * from (select u.*from userinfo u where id>0 order by id desc
) where rownum<=3;
按id从大到小 取后三行
答案:
select * from (select u.* from userinfo u where id>0 order by id
) where rownum<=3 order by id desc;
你学费(hui)了吗?
orcale 数据库语句(一)相关推荐
- ORCALE数据库分页查询
ORCALE数据库分页查询 ORCALE数据库实现分页查询可以使用row_number()函数或者使用rownum 虚列两种方法. 第一种:利用分析函数row_number() 方法 select * ...
- Orcale数据库简介
关于关系数据库: 数据库管理系统(DBMS) :是一种软件,用于对数据的存储,组织和检索 它具有以下元素: 1.内核代码 DBMS用来管理内存和储蓄 2.元数据的储存库 就是数据字典:是描述数据信息的 ...
- java连接Orcale数据库并查询、插入、删除数据
java连接Orcale数据库并查询.插入.删除数据 oci和thin是Oracle提供的两套Java访问Oracle数据库方式. thin是一种瘦客户端的连接方式 oci是一种胖客户端的连接方式 J ...
- oracle 数据库中执行数据库语句能找到数据,但是程序中却抓取不到
oracle 数据库中执行数据库语句能找到数据,但是程序中却抓取不到? 原因:数据库中插入数据时没有commit,执行COMMIT后就可以查询到. 转载于:https://www.cnblogs.co ...
- excel的mysql语言_Excel的数据库语句
我现在用Excel当数据库,在里面建立一个表格,能访问成功,能查询,就不是能添加,删除和修改,是不是Excel和SQL得数据库语句不一样?我用的是SQL语句访问的,能查询,其他的功能就不... 我现在 ...
- MySQL数据库——语句
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言 一.MySQL数据库语句 (一).按关键字排序 1.可进行多字段的排序 (二).单字段排序 1.按分数排序,默认不指定 ...
- 讲解SQL数据库语句
前言 大家好,我是 Vic,今天给大家带来讲解SQL数据库语句的概述,希望你们喜欢 数据库语句 create database teach; use teach; create table `teac ...
- mysqldump备份数据库语句
mysqldump备份数据库语句 语法: Usage: mysqldump [OPTIONS] database [tables] OR mysqldump [OPTIONS] --datab ...
- QT学习 (MYSQL数据库语句操作)
一. 使用Navicat工具操作数据库 工具下载地址:https://download.csdn.net/download/dianzishi123/10805940 有一个可连接使用的数据库 打开工 ...
最新文章
- 用路由器限制局域网的带宽流量
- 【手记】解决启动SQL Server Management Studio 17时报Cannot find one or more components...的问题
- 【逆天的算法】这几首宋词,你能看出来是出自计算机之手吗?
- 目标检测 nms非极大抑制算法
- Intel Realsense D435 hardware_reset() 摄像头重置记录 context.query_devices()
- Hadoop 使用自动化脚本启动hdfs和yarn
- mysql unicode转汉字_Mysql数据库表引擎与字符集
- mysql数据库有触发器吗_MySQL数据库之MySQL 触发器实现
- python爬取糗事百科
- MySQL关闭查询缓存(QC)的两种方法
- Androd开发之广告栏设计
- Linux中实现远程登录Xshell和Xftp
- Win7系统下调整硬盘分区大小给C盘更多的空间
- H.266/VVC代码学习:xCheckRDCostMerge2Nx2N函数
- Dell Inspiron 3443 BIOS升级问题解决
- vb.net 教程 3-1 窗体编程基础 2
- Firefox七种武器之firebug
- transition属性
- 转-iOS- GPUImage README.md
- 国外服务器 虚拟主机,虚拟主机国内国外什么区别
热门文章
- 云安全实现高效预防 未来之路怎么走?
- PPTV(pplive)_forap_1084_9993.exe 木马清除经历
- 工业机器人的自由度轴向如何定义
- Java Netty 4.x 用户指南
- python两层循环 循环完整体一个_Python学习教程(Python学习路线):Python编写循环的两个建议...
- ip地址、网关、子网掩码和MAC
- 中国电信IT研发中心 2019校园招聘笔试F卷 编程题-2018.09.10
- ffplay flv mp4 转_ffmpeg转换mp4到flv的使用笔记
- 基于Basys2开发板的简易电子琴和音乐播放器设计
- Android Java小知识点集锦