以TO_DATE命令作为数据库值的字符串 [英] Strings with TO_DATE command as value on the database

查看:119
本文介绍了以TO_DATE命令作为数据库值的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,但现在还不能解决.在我的数据库上,我有字符串:

I have a problem and I can't solve it yet. On my database I have the string:

TO_DATE(' 2015-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN').

因此,在构建查询时,它类似于以下内容:

So when I'm building my query it is like the following:

Select my_field FROM my_table.

结果是:

TO_DATE(' 2015-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')

明白吗?

如何在选择查询中提取此字段的值作为命令语句?

How to I extract the value of this field as a command statement on a select query?

推荐答案

我可以解决问题.我正在搜索动态SQL,并选择了正确的plsql以获取结果.

I could solve the problem. I was searching for Dynamic SQL and I made the right plsql to get the result.

由于该表可能会有一个以上的结果,所以我使用了CURSOR来创建一个类型. (TYPE tpT IS REF CURSOR; cCursor tpT;)然后,我进行查询(vSQL)并使用OPEN cCursor FOR vSQL运行它;然后我对结果的任何实例进行了循环处理.因此在LOOP内,当AUX具有字符串TO_DATE(' 2015-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN').时,我做了一个EXECUTE IMMEDIATE 'SELECT ' || AUX || ' FROM DUAL' INTO DATE_AUX.然后var DATE_AUX的值为'01-MAR-15'.

As the table could have more then one result I used a CURSOR to make a type. (TYPE tpT IS REF CURSOR; cCursor tpT;) Then I made my query (vSQL) and run it with OPEN cCursor FOR vSQL; then I did a Loop to any of the instances of the result. So inside the LOOP I did a EXECUTE IMMEDIATE 'SELECT ' || AUX || ' FROM DUAL' INTO DATE_AUX, when AUX have the string TO_DATE(' 2015-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN').. Then the var DATE_AUX has the value '01-MAR-15'.

感谢您提供的所有帮助.感谢@ justin-cave,@ jim-mcnamara和@ dan-bracuk.抱歉,我的信息一塌糊涂.

Thank you for all the help. Thanks @justin-cave, @jim-mcnamara and @dan-bracuk for your time. And I'm sorry for the mess of information.

这篇关于以TO_DATE命令作为数据库值的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆