zoukankan      html  css  js  c++  java
  • 第十二天 SQL语句 查询

    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; []<>()都可以

  • 相关阅读:
    Lambda Expression in C#
    DirectorySearcher LDAP
    摘录 LDAP
    The return types for the following stored procedures could not be detected
    无法调试存储过程,无法启动T-SQL调试
    根据窗口句柄显示窗体
    还原数据库时提示空间不足
    xml格式发送
    ../ 上一级目录
    匿名函数 invoke
  • 原文地址:https://www.cnblogs.com/shan2017/p/7246758.html
Copyright © 2011-2022 走看看