with tmp as ()
后面直接接update的时候会报错,没发现select
本来想着
with tmp as ()
update
set col1 = ( select tmp.col from tmp ),
set col2 = ( select tmp.col2 from tmp ),
...
where col3 in ( select tmp.col3 from tmp )
....
执行报错了,没有select,这个应该大家都发现了
然后呢
我换了个法子
update
set col1 = ( with tmp as ()
select tmp.col from tmp ),
set col2 = ( select tmp.col2 from tmp )
...
where col3 in ( select tmp.col3 from tmp )
....
我告诉你,这个语句看起来跟奇怪但是,它是可以执行的,而且不报错
是不是很神奇啊,
虽然这个语句看起来很奇怪,但是,它真的是可以执行的
神奇吧
那么,你是不是觉得峰回路转,with as与update可以用了呢?
其实不然啊
我试了执行了一下,结果为0
但是我不用with as 居然执行结果是18
这里你们明白了嘛
还是不可以执行
当然,也可能是我的技术不好,或者我是不是没考虑update语句的执行顺序
我是不是应该把with as 放到where里面去呢
update
set col1 = ( select tmp.col from tmp ),
set col2 = ( select tmp.col2 from tmp )
...
where col3 in ( with tmp as ()
select tmp.col3 from tmp )
....
这样不知道行不行本来是想试试的
结果发现,刚才执行没有with as的时候被commit了
然后,测试数据没有了,造起来很麻烦
所以,有兴趣的自己找个场景试试吧,我觉得应该也是不行的
最近加班有点累,前天加班到三点,昨晚还被拖到八点多,有点晕,脑袋转不动了。就这样
最最关键的还是oracle 不支持update from啊
不然
哪要这么纠结呢