需要熟悉的语句

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

select file_name from dba_data_files;


2.查询表空间的名字

select tablespace_name from dba_tablespaces;

3.查看表中有哪些 字段

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

4.查询链接到了哪个 数据库实例
  select name from v$database;

5. (1)使用用户scott/tiger 链接到数据库,然后指定链接的实例名为orcl
   (2)使用用户system/tiger链接到数据库,然后指定以dba身份链接
   (3)关闭链接
 
   (1)conn scott/tiger@orcl;
   (2) conn system/tiger as sysdba;
   (3)disconnect

6. 清屏命令

clear screen;

7.查看当前用户是谁

show user;


8.返回 当前日期,时间,格式为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,和 工作月数(截断)

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


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


12.查询employees表,使用 正则表达式显示以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,以及 其他所有部门名

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表,显示每个部门每个岗位的 平均工资,部门 平均工资以及所有雇员 平均工资

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表,显示部门 平均工资以及岗位平均工资。
select department_id,job_id ,avg(salary) from employees group by grouping sets(department_id,job_id);

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

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

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

select emloyee_id from employees intersect select employee_id from job_history;

你可能感兴趣的:(数据结构,oracle,工作,正则表达式)