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

  • 相关阅读:
    数据仓库与数据挖掘的一些基本概念
    System.currentTimeMillis();
    html练习(3)
    HDU 1556 Color the ball【算法的优化】
    ubuntu12.04 安装配置jdk1.7
    java中的switch用String作为条件
    oracle中 connect by prior 递归算法
    C#复习题
    AngularJS:Http
    AngularJS:Service
  • 原文地址:https://www.cnblogs.com/shan2017/p/7246758.html
Copyright © 2011-2022 走看看