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

  • 相关阅读:
    harbor1.9仓库同步迁移
    接口强制删除namespace 为Terminating的方法
    k8s 命令自动补全
    docker harbor 搭建&配置http/https 方法
    docker harbor 清理释放存储空间
    强化学习系列
    Kaggle的Outbrain点击预测比赛分析
    talkingdata比赛分析
    keras模型总结
    深度神经网络多任务学习(Multi-Task Learning in Deep Neural Networks)
  • 原文地址:https://www.cnblogs.com/shan2017/p/7246758.html
Copyright © 2011-2022 走看看