20170727上课笔记

DML 增删查改 不改变表结构

DLL 修改表结构

  1. 查看hr用户名下的表,解锁hr用户:

$ sqlplus / as sysdba或SQL> conn / as sysdba

SQL> show user

SQL> select table_name from dba_tables where owner='HR'; 查询hr下有多少表

SQL> select * from hr.employees;

SQL> alter user hr account unlock identified by hr;//解锁口令hr 并且为其赋值登录密码为hr

$ sqlplus hr/hr或者SQL> conn hr/hr

SQL> show user

SQL> select * from tab;

SQL> desc employees 查看表结构

  1. 使用sqlplus的全屏编辑功能:

$ echo $EDITOR

SQL> select * from hr.employees;

SQL> ed//vi编辑模式进行编辑sql语句保存退出后/执行该语句

SQL> /                         执行

select 字段a,字段b from table

select 字段a||字段b from table  //合并两列显示

select 字段a||','||字段b from table //合并两列,且中间,隔开

desc 表 //查看字段

grant select on hr.employees to user01 //将hr的查询权限赋予user01

select‘grant select on hr.'||table_name||' to user01;’from user_tables; //将hr所有表权限赋予user01

spool /home/oracle/grant.sql //以后所有文件的输出都会在grant文件中存留

set head off // grant脚本输出关掉开头

set feed off//grant脚本输出关掉末尾

正文中'要‘’表示或者 select q'[test'test]' from dual; 或者{},(),<>都可达到效果

select distinct 字段a from 表 //字段a若有重复 去除重复

lower()全部转换小写

to_date('2006-5-11','yyyy-mm-dd');//日期格式转换

.bash_profile //服务器日期格式修改在此文件中

alter session set nls_date_format='RR-Mon-dd';//修改此会话中日期格式

当查询条件like'st_%' //%钱的_代表特殊含义(任意单字符),所以用like'st\_%' _前加转义符

is null 不代表=''

and优先级大于or

原文地址:https://www.cnblogs.com/guoxf/p/7245862.html