Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 创建过程并从两列更新_Sql_Oracle - Fatal编程技术网

Sql 创建过程并从两列更新

Sql 创建过程并从两列更新,sql,oracle,Sql,Oracle,我有两个表A和B,如果A中的C=C=B中的C,如果LB减去LA>=2小时,我将不从A更新到D,设置D=0 合并可能是您的选择之一: SQL> create table a (c number, d number, la date); Table created. SQL> create table b (c number, lb date); Table created. SQL> insert into a 2 (select 12345, 30, to_d

我有两个表A和B,如果A中的C=C=B中的C,如果LB减去LA>=2小时,我将不从A更新到D,设置D=0


合并
可能是您的选择之一:

SQL> create table a (c number, d number, la date);

Table created.

SQL> create table b (c number, lb date);

Table created.

SQL> insert into a
  2    (select 12345, 30, to_date('01.04.2018 20:10', 'dd.mm.yyyy hh24:mi') from dual);

1 row created.

SQL> insert into b
  2    (select 12345, to_date('01.04.2018 18:00', 'dd.mm.yyyy hh24:mi') from dual);

1 row created.

SQL>
SQL> merge into a
  2    using (select b.c, b.lb from b) x
  3    on (a.c = x.c and
  4        (a.la - x.lb) * 24 >= 2
  5       )
  6  when matched then
  7    update set a.d = 0;

1 row merged.

SQL>
SQL> select * From a;

         C          D LA
---------- ---------- ----------
     12345          0 01.04.2018
阻止更新的值:

SQL> delete from a;

1 row deleted.

SQL> insert into a
  2    (select 12345, 30, to_date('01.04.2018 19:10', 'dd.mm.yyyy hh24:mi') from dual);

1 row created.

SQL> merge into a
  2    using (select b.c, b.lb from b) x
  3    on (a.c = x.c and
  4        (a.la - x.lb) * 24 >= 2
  5       )
  6  when matched then
  7    update set a.d = 0;

0 rows merged.

SQL> select * From a;

         C          D LA
---------- ---------- ----------
     12345         30 01.04.2018

SQL>