select查询语句
- 查看hr用户名下的表,解锁hr用户:
$ sqlplus / as sysdba或SQL> conn / as sysdba
SQL> show user
SQL> select table_name from dba_tables where owner='HR';
SQL> select * from hr.employees;
SQL> alter user hr account unlock identified by hr;
$ sqlplus hr/hr或者SQL> conn hr/hr
SQL> show user
SQL> select * from tab;
select * from employees;
SQL> desc employees 查看表结构
练习:
查看scott用户名下的表,解锁scott用户:
scott/tiger
- 使用sqlplus的全屏编辑功能:
$ echo $EDITOR
SQL> select * from hr.employees;
SQL> ed
SQL> / 执行
- 基础select语句:
SQL> select * from employees;
SQL> desc employees
SQL> select LAST_NAME, SALARY, COMMISSION_PCT from employees;
SQL> desc departments
SQL> select department_id, department_name from departments;
SQL> select distinct DEPARTMENT_ID from employees;
SQL> select last_name, salary*12*(1+commission_pct) total_salary, department_id from employees;
SQL> select first_name||', '||last_name from employees;
SQL> select first_name||', '||last_name fullname from employees;
练习:
输出下列员工信息:
Eleni(first_name) Zlotkey(last_name) employeeid is ... at department .. total salary is …
- 使用连字符构造语句:
SQL> select table_name from user_tables;
SQL> select 'grant select on hr.'||table_name||' to scott;' from user_tables;
SQL> spool /home/oracle/grant.sql
SQL> select 'grant select on hr.'||table_name||' to scott;' from user_tables;
SQL> spool off
$ vi /home/oracle/grant.sql 去除没用的行
SQL> @/home/oracle/grant.sql
- 单引号的处理:
SQL> select 'I'm teaher' from dual;
ERROR:
ORA-01756: quoted string not properly terminated
SQL> select 'I''m teaher' from dual;
SQL> select q'{I'm teaher}' from dual; []<>()都可以