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

  • 相关阅读:
    Vue2.x源码学习笔记-Vue构造函数
    微服务从设计到部署(七)重构单体为微服务
    微服务从设计到部署(六)选择部署策略
    Spring REST API + OAuth2 + AngularJS
    微服务从设计到部署(五)事件驱动数据管理
    REST:JAX-RS 与 Spring
    微服务从设计到部署(四)服务发现
    了解 Spring Boot AutoConfiguration
    微服务从设计到部署(三)进程间通信
    微服务从设计到部署(二)使用 API 网关
  • 原文地址:https://www.cnblogs.com/shan2017/p/7246758.html
Copyright © 2011-2022 走看看