Oracle基础知识

初识SQL

DESC

  1. 查看表结构
conn scott/tiger  -- 登录Scott用户
select * from tab  -- 查询该数据库(用户)下的表
desc tb1  -- 查询表结构【只能在command下执行,否则报错】

DISTINCT

消除重复列【重复列指的是该行的查询出的数据都一样】

SQL查询

空判断

select * from emp where comm IS NOT NULL;

null属于一个未知的数据,与任何数字计算都会得到null

select * from emp where comm in (10,200,null)

模糊查询

  • -: 匹配任意的一位字符
  • %:匹配任意位的符号
select * from emp where name like 'A%'

like可以在任意数据类型上使用

Oracle单行函数

字符串函数

  1. 大小写转换
  • LOWER(column | 字符串)
  • UPPER(column | 字符串)
select lower('hello') as name from dual;
select * from bm_user where name=upper(#name) --Mybatis
  1. 首字母大写
  • initcap
SQL> select initcap('hello') as name from dual;
NAME
-----
Hello
  1. 字符串长度
  • length()
select * from bm_user where length(name) = 5;
  1. 字符串替换
  • replace(column|字符串, 要查找的字符串,新的内容)
SQL> select replace('hello world!','llo','LLO') as name from dual;

NAME
------------
heLLO world!

消除空格

  1. 字符串截取
  • substr(str, startIndex) : startIndex标识下表,从1开始
  • substr(str, startIndex, length)
SQL> select substr('hello world!',7) as name from dual;

NAME
------
world!

数值函数

日期函数

  1. 获取系统日期
select to_char(sysdate,'yyyymmddhh24miss') from dual;  -- 24小时

转换函数

通用函数

多表查询

内连接

表1,emp [empno, ename, deptno]

表2,dept [deptno, dname, loc]

select * from emp, dept

创建数据库

以前开发的时候用得比较多的是mysql和sql server,oracle用的比较少,用起来比较生疏,mysql和sql server用起来比较类似.

就oracle的使用方式和他们不同,oracle在创建数据库的时候要对应一个用户,数据库和用户一般一一对应,mysql和sql server 直接通过create databse “数据库名” 就可以直接创建数据库了,而oracle创建一个数据库需要以下三个步骤

  1. 创建两个数据库的文件
  2. 创建用户与上面创建的文件形成映射关系
  3. 给用户添加权限
原文地址:https://www.cnblogs.com/zhuxiang1633/p/11773719.html