數據庫查詢命令+簡單函數

sql基本語句

  • select  * from  + 表名   (後跟where條件)
  • select  字段1,字段2,字段3 from  (後跟where條件)
  • select  *   from   + 表名   where  user  in  'zhu'    查詢zhu這個用戶所有信息
  • select  t.user  as 用戶 ,t.tel 電話  from  + 表名  將查詢到的字段另命名
  • create database zhu ;    創建名爲朱的數據庫
  • show tables;     顯示數據庫中的表
  • create table  zhu  ( id NUMBER(32) not null,name NVARCHAR2(64),password NVARCHAR2(64),phone_number NVARCHAR2(20)) 創建名爲zhu 的表  後跟字段1.類型1
  • up date 更新表   select  * from   zhu   where  id= ''1  for update   跟新id爲1的東西
  • insert into 表名(列1) values (值1)
  • alter name rename as name1    將renane  重命名爲name1
  • delete from 表名;   刪除這個表中所有記錄,但表的定義不動
  • delete from 表名    where 列名=條件    僅刪除符合條件的記錄
  • drop table 表名       刪除這個表,連同裏面的數據
  • update + 表名  set  date = '20191212'  將date這個字段所有日期更新爲20191212

數據庫函數

  • substr  截取字符函數   select substr (t.matnr,6,9)  from  + 表名從第6位截取到第9位
  • sum    求和函數     select  sum (xiaol)   from  +  表名   對銷量進行求和
  • count  統計函數    select  count (xiaol) from  + 表名   where xiaol = '0'  統計銷量位0的有幾個
  • disable  去重函數   select  disable  werksf,xiaol  from  + 表名  where  ....  對 werksf  去重複的
  • avg  平均數函數   select avg (xiaol)  from + 表   where    對xiaol求平均數
  • union  all  合併函數
  • nvl  函數  NVL(expr1,expr2),替換NULL值,如果expr1爲空值,則返回expr2的值,否則返回expr1的值。該函數要求兩個參數類型一致至少相互之間可以進行隱式的轉換
  • decode 函數 decode(條件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值)  
  •  

多種日期格式

  • YYYY:四位表示的年份
  • YYY,YY,Y:年份的最後三位、兩位或一位,缺省爲當前世紀
  • MM:01~12的月份編號
  • D:星期中的第幾天
  • DD:月份中的第幾天
  • DDD:年所中的第幾天
  • to_char():將日期轉按一定格式換成字符類型    TO_CHAR(t1.logintime, 'yyyymmdd') = '20191101'
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章