需要熟悉的语句

[color=blue][/color][color=blue]1.查询所有数据文件(Oracle的物理结构)的名字[/color]

select file_name from dba_data_files;


[color=blue]2.查询表空间的名字[/color]

select tablespace_name from dba_tablespaces;

3.查看表中有哪些[color=blue]字段[/color]

desc v$instance; 可以查看v$instance这个视图的信息

4.查询链接到了哪个[color=blue]数据库实例[/color]
select name from v$database;

5. (1)使用用户scott/tiger[color=blue]链接到数据库[/color],然后指定链接的实例名为orcl
(2)使用用户system/tiger链接到数据库,然后指定以dba身份链接
(3)关闭链接

(1)conn scott/tiger@orcl;
(2) conn system/tiger as sysdba;
(3)disconnect

6. [color=blue]清屏命令[/color]

clear screen;

7.查看当前用户是谁

show user;


8.返回[color=blue]当前日期[/color],时间,格式为2005/04/05 20:08:10

select to_char(sysdate,'YYYY/MM/DD HH24:MI:SS') from dual;

9. 查出hiredate在1999年后的。。。。

hiredate >= '1-1月 -99'

10.查询employees表,显示部门100所有员工的first_name,和[color=blue]工作月数[/color](截断)

select first_name, TRUNC(MONTHS_BETWEEN(sysdate,hire_date)) months from employees where department_id=100;


11.把hire_date转化为[color=blue]工作日[/color]
to_char(hire_date,'DAY')----效果是: 星期三


12.查询employees表,使用[color=blue]正则表达式[/color]显示以S开头,en结尾的雇员First_name和last_name.

select last_name ,first_name from employees where regexp_like(first_name,'^S\w+en$');

13. 查询departments 表,显示部门100的部门名及其雇员的first_name,以及[color=blue]其他所有部门名[/color]。

select a.department_name,b.first_name from departments a left join employees b
on a.department_id = b.department_id and a.department_id = 100;

左联接就是把左边不与where子句匹配的也都查上

14.查询employees表,显示每个部门每个岗位的[color=blue]平均工资[/color],部门[color=blue]平均工资[/color]以及所有雇员[color=blue]平均工资[/color]。

select department_id,job_id ,avg(salary) from employees group by rollup(department_id,job_id);

也就是以department_id,job_id作为分组,然后小计分组的avg(salary),然后再总计所有的salary

15.查询employees 表,显示每个部门每个岗位的平均工资,部门平均工资,岗位平均工资以及所有雇员平均工资。
select department_id,job_id ,avg(salary) from employees group by cube(department_id,job_id);

16.查询employees表,显示部门[color=blue]平均工资[/color]以及岗位平均工资。
select department_id,job_id ,avg(salary) from employees group by grouping sets(department_id,job_id);

助记: grouping sets意味着需要的是分组结果集

17.查询employees表和job_history表,使用[color=blue]集合操作符[/color]显示更换过工作的雇员的雇员号

思路: 如果更换过工作,那么会在job_history表中出现他的名字

select emloyee_id from employees [color=blue]intersect[/color] select employee_id from job_history;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值