SAVEPOINT 在循环中的独立性

2019年11月24日 没有评论

官方对SAVEPOINT的说明:
Use the SAVEPOINT statement to identify a point in a transaction to which you can later roll back.
简单的理解就是可以部分提交事务
官网的一个例子:

UPDATE employees
    SET salary = 7000
    WHERE last_name = 'Banda';
SAVEPOINT banda_sal;

UPDATE employees
    SET salary = 12000
    WHERE last_name = 'Gre[......]

继续阅读。。。

分类: Oracle, PL/SQL 标签:

Oracle 分析函数

2019年1月6日 没有评论

1. 分析函数前传之聚合函数

1.1 聚合函数定义

Aggregate functions return a single result row based on groups of rows

Aggregate functions return a single result row based on groups of rows, rather than on single rows. Aggregate functions can appear in select lists and in ORDER BY and HAVING clauses. They are commo[......]

继续阅读。。。

分类: Oracle, Oracle SQL 标签: , ,

Oracle SQL 基础培训

2019年1月1日 没有评论

1.SQL基础

1.1 基础语法

  • create table
  1. 普通表
 create table ANGU_TEST1
(
  id NUMBER
)
tablespace USERS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

  1. 临时表
 --基于回话
create global temporary table ANGU_TEMP
(
  id NUMBE[......]

继续阅读。。。

分类: Oracle, PL/SQL 标签:

利用Oracle UnPivot 实现自定义的行转列

2018年12月24日 没有评论

以下是测试数据

create table Fruit
(id int,name varchar(20),
Q1 int, Q2 int,
Q3 int, Q4 int);

insert into Fruit values(1,'苹果',1000,2000,3300,5000);
insert into Fruit values(2,'橘子',3000,3000,3200,1500);
insert into Fruit values(3,'香蕉',2500,3500,2200,2500);
insert into Fruit values(4,'葡萄',1500,2500,1200,350[......]

继续阅读。。。

分类: Oracle SQL 标签: ,

聚合函数报错

2018年2月10日 没有评论

最近在工作中遇到一个很奇怪的问题,代码使用了Oracle的sum函数,可在程序运行中,抛了一个很奇怪的异常:ORA-01403: no data found,通常来说即使没有任何数据,最多结果应该是null,也是有值的。
- 测试代码:

  declare
    s_sal NUMBER;
  begin
    SELECT sum(t.salary)
     INTO s_sal
     FROM emp t WHERE 1 =2 ;
   EXCEPTION WHEN OTHERS THEN
     dbms_output.put_line(sqlerrm);
  end;

[......]

继续阅读。。。

分类: Oracle SQL 标签: ,