数据库查询命令+简单函数

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'
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章