1. 程式人生 > >20170727上課筆記

20170727上課筆記

bsp 所有 會話 去除 退出 日期格式 distinct 服務 並且

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

20170727上課筆記