oracle对一种sql写法的支持很有意思,求解!
因为不小心,写出这一类SQL来,发现很奇怪:
select count(1) from dual where+dummy is not null;
经过一番尝试,发现select和where后都可以这么写,至于其它关键字后的情况,还没有尝试过:
select+nvl(dummy,''),+dummy,+1 from dual where+1=1 and+dummy is not null and +dummy is not null;
起初以为,只是因为pl/sql有过滤功能,所以可以这么写SQL,后来发现在程序里也可以这样写。说明oracle是支持这种写法的。标准SQL语法里没见过,这样写的,至于为什么能这么写,在baidu和google里,都没有解释。
用length等函数测试过,感觉和select null || nvl(dummy,'') a, null || dummy b,nll || 1 from dual where null || 1=1 and null || dummy is not null; 等效的(和chr(0)连接就不对了),但不同的是,使用加号情况,两关键字之间可以不需要空格。所以还是有些区别的。
有了这么变态的SQL写法,在程序里写动态SQl时,就可以用 "where+dummy is not null" 代替 "where 1=1 and dummy is not null"了,不过这不是标准写法,不敢轻易使用。
为什么能这么做? 应该不会是oracle的BUG,但oracle也不会支持这么无聊的写法,另外还有哪些符号也有支持这种写法呢? 求各位大侠指点啊。