oracle sql相关语法

SQL*PLUS

在SQL*PLUS执行,会在执行后显示查询的执行计划和统计信息

SET AUTOTRACE ON;

SELECT * FROM your_table WHERE column_name = 'value';

SET AUTOTRACE OFF;

PLSQL

PLSQL查询sql界面,鼠标右键,点击执行计划,会出现sql的执行计划结果

SELECT * FROM your_table WHERE column_name = 'value';

oracle sql相关语法_第1张图片

oracle SQL查询表索引信息

SELECT c.INDEX_NAME,
       CASE UNIQUENESS
           WHEN 'UNIQUE' THEN 'Unique Index'
           WHEN 'NONUNIQUE' THEN 'Non-Unique Index'
           ELSE 'Unknown'
       END AS INDEX_TYPE,
       LISTAGG(COLUMN_NAME, ', ') WITHIN GROUP (ORDER BY COLUMN_POSITION) AS INDEX_COLUMNS
FROM USER_IND_COLUMNS C
JOIN USER_INDEXES I ON C.TABLE_NAME = I.TABLE_NAME AND C.INDEX_NAME = I.INDEX_NAME
WHERE c.TABLE_NAME = ''
GROUP BY c.INDEX_NAME, UNIQUENESS;

instr函数

instr(config_desc, ‘,’)=0
其中如果config_desc为null,表达式的值为null,字符串未找到为0

select instr(null,',');-- null
select instr('null',','); -- 0
select instr('null,null,',','); -- 0

unistr函数

Unicode转字符串
SELECT UNISTR(‘\00a0’) from dual;

子查询

标量子查询

子查询的结果有且仅有一条
SELECT column1, (SELECT MAX(column2) FROM table2) AS max_value
FROM table1;

--子查询结果不为1条
-- 列中子查询
select id,
(select password from users) 
from users group by id;

-- where条件子查询
select id
from users  where id > (select id from users)

oracle sql相关语法_第2张图片

表子查询

执行顺序优于主查询
SELECT column1
FROM (SELECT column2 FROM table2 WHERE condition) AS subquery;

你可能感兴趣的:(oracle,sql,数据库)