oracle数据库常用操作语句

新增字段:alter table 表名 add

(NAME VARCHAR(12),

VALUE  NUMBER(10)

);

添加注释:comment on column 表名.name is '姓名';

删除表字段:alter table 表名 drop column 字段名(列名);

修改字段名:alter table 表名 rename column 现列名 to 新列名;

删除字段名:alter table 表名 drop column 字段名

 

NVL(a,b): a不为null,结果为a,否则为b。

NVL2(a,b,c) :a不为null, 结果为b, 否则为c。

 

function:vempid mytable.id%type;//vempid参数的数据类型跟mytable表的id字段类型一样,当你修改mytable表的ID字段类型,就不用修改function了
 
 
procedure:newID in mytable.id%type//newId参数的数据类型跟mytable表的id字段类型一样,当你修改mytable表的ID字段类型,就不用修改procedure了

删除函数:drop function 方法名;

 

minus  :A minus B 即在A中存在,而在B中不存在的记录。例如  

select  id  from a
minus
select  id  from b

只获取系统日期,不要时分秒
select trunc(sysdate) from dual //这样得到的格式如:2018/08/02

 declare匿名函数

declare

v_avgsal number(6,2);//定义变量

begin

//sql语句

end;

oracle自治事务 :AUTONOMOUS_TRANSACTION

去掉回车换行符:chr(10)是换行符,chr(13)是回车,制表符 chr(9)

replace('去掉

换行符 ',chr(10),'')

 oracle 打印输出   :

dbms_output.put_line('需要输出的内容');

 select * from 表 where 字段 is null   : oracle会查询返回‘’和null的数据。oracle对空字符和null是一个意思

 快速新建一个表一模一样的表,并把数据插入。create table newtablename as select * from oldtablename;

 

Merge into用法

merge into 目标表 a
 
using 源表 b
 
on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……)  
 
when matched then 
update set a.更新字段=b.字段

when  not macthed then 
insert into a(字段1,字段2……)values(值1,值2……)
macthed或not macthed语句可以只有一个。参考: https://blog.csdn.net/spw55381155/article/details/79891305

 PLSQL : https://baike.baidu.com/item/plsql/9042661?fr=aladdin

https://blog.csdn.net/wahaa591/article/details/46648365

 

转载于:https://www.cnblogs.com/Alwaysbecoding/p/9177761.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值