comment on table *** is '表的注释汉字名'
comment on column table.column is '某表的某属性后加注释';
constraint **name primary key(colum);设置主键
constraint **name foreign key(本表column) references dept(外表column);引用外键
补充表内容
alter table *** add ------- ---为类似于 constraint的这种语句,当表创建完成时,对表进行的补充
to_data('08-09-2018','dd-mm-yyyy') 类型转换,前转后
to_char 转字符串
虚标 dual
为了执行函数所使用的虚表 select to_char() from dual
模糊查询 like %
select * from dept where dname like '生%'; like代替= %代替省略字
排序显示
order by column_name asc/desc 不写的话默认是asc即升序,desc为降序
多列排序,即在按照第一个列排序后,再按第二列进行排序 order by column_name1,column_name2
基本函数
count求行数 sum求和 max最大 min最小 avg平均
集合操作 union 与 union all
sql union sql2 ,必须列数相同 如果是union是去重复,如果是union all 是全部打印
序列
create sequence name increment by x //x为增长间隔
start with x //x为初始值
maxvalue x //x为最大值
minvalue x //x为最小值
cycle //循环使用,到达最大值或者最小值时,从新建立对象
cache x //制定存入缓存(也就是内存)序列值的个数
cache的作用:当大量语句发生请求,申请序列时,为了避免序列在运用层实现序列而引起的性能瓶颈。
Oracle序列允许将序列提前生成 cache x个先存入内存,
打印当前时间,并更改各种格式
select sysdate from dual;
select to_char(sysdate,'yyyy-mm-dd hh:mm') from dual;
过程 函数 触发器
create or replace procedure p1()
is
begin
end
create or replace function f1()
return is
begin
return **
end
create or replace trigger t1
before delete
on emp for each row
begin
end
几个常用的函数 ( 参考此位大佬总结https://www.cnblogs.com/xingminghui/p/7966005.html)
substr(字符串,开始位置,结束位置)用于从一段字符串里截取出一部分
NVL(x,value) 若x为空,则返回value
NVL2(x,value1,value2) 若x非空,返回value1,否则返回value2
select * from table where rownum=数字 查第几行的数据