Converting CLOB to NUMBER to compare - Oracle

旧巷老猫 提交于 2019-12-12 18:51:05

问题


I'm newbie to oracle and my question is easy, is possible to convert a CLOB field into NUMBER type to do a comparison.

I´ve tried using CAST and also with TO_NUMBER function but i did not get nothing working.

My attempts:

WHERE TO_NUMBER(clob_field) = 100 -> Error ORA-01722: NOT a valid number

WHERE CAST(clob_field as NUMBER) = 100 -> Error ORA-00932:Inconsistent datatypes

If this is not possible, which would be the best approach to do this?

Thanks for your time and help.


回答1:


Compare it as varchar to get rid of the error message:

WHERE TRIM(clob_field) = '100'

If there is never any whitespace around the 100 you can skip the TRIM:

WHERE clob_field = '100'



回答2:


Cast it first to a VARCHAR2 and then to a NUMBER:

CAST(CAST(clob_field AS VARCHAR2(200)) AS NUMBER(10))


来源:https://stackoverflow.com/questions/22150212/converting-clob-to-number-to-compare-oracle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!