基本操作
- 查询当前用户创建的所有的表: select * from user_tables;
- 查询当前用户能够访问的所有的表: select * from all_tables;
- 创建表:
create table stu(
id number(10),
name varchar2(20),
sex varchar2(20),
age number(10),
address varchar2(20)
); - 插入新记录:
insert into stu values (1, 'tom', 'male', 18, 'beijing'); - 查询表中的全部数据:
select * from stu; - 查看表结构:
desc(ribe) stu; - 删除表中数据:
delete from stu; - 删除表:
drop table stu; - 插入空值:
insert into stu values (1, 'zhangsan', 'male', 18, null); - 查询时去除重复行:
select distinct age from stu; - 单字段升序:
select * from stu order by age asc; - 单字段降序
select * from stu order by age desc; - 多字段组合排序
select * from stu order by id asc,age desc; - 排序中的空值
在Oracle数据库中默认null为最大值,所以升序null值放在最后面, 降序null值放在最前面
始终将null值放在最前面
select * from stu order by age desc nulls first; - 始终将null值放在最后面
select * from stu order by age asc nulls last; - 查询指定字段的数据
select name,sex from stu; - 比较运算符
- 模糊查询
%(百分号)-----表示零个或多个任意字符的通配符
_(下划线)-----表示单字符的通配符
查询名字以w开头的记录
select * from stu where name like 'w%';
查询字句中包含"_"的记录
select * from stu where name like '%\_%' escape '\';
用escape标识符指明“\”为转义字符