Oracle 链接查询返回奇怪的值
我正在开发查询 Oracle Link Server 并返回值的存储过程。 如果我复制屏幕上打印的语句并在 Oracle SQL Developer 上运行,它将正确返回数字。
但是当我将其作为链接查询运行时,它返回错误的数字。我完全迷失了。
DECLARE @MDX NVARCHAR(MAX)
DECLARE @stmt NVARCHAR(MAX)
SET @MDX = dbo.fnCrseReviewDiversityDataStarts(117)
Set @stmt = 'SELECT * FROM OpenQuery(ORA_Link, ''' + REPLACE(@MDX, '''', '''''') + ''')'
PRINT @MDX
EXEC (@stmt)
请忽略上面的SQL语句。我直接使用了下面的sql,但它不起作用。我发现 Months_ Between 函数不像在 OracleServer 中那样工作。
SELECT * FROM OpenQuery(ORA_LINK, 'select t2.s_studentreference "Student reference",
to_char(t3.e_start,''YYYY'') "Start",
t1.p_dob,
''31-Aug-''||to_char(t3.e_start,''YYYY'') "StartDate",
months_between(t1.p_dob,''31-Aug-''||to_char(t3.e_start,''YYYY'')) "DifferenceMonths"
from capd_student t2,capd_person t1,capd_moduleenrolment t3
where t2.s_id(+)=t1.p_id and (t3.e_student=t1.p_id) and (t3.e_reference=to_char(1109315))
and t3.e_status = ''L'''
);
I am developing the Store procedure which queries the Oracle Link Server and returning values.
If I copy the statement which is printed on the screen and run on the Oracle SQL Developer, it returns the figure correctly.
But when I run that one as the link query, it returns wrong figure. I am completely lost.
DECLARE @MDX NVARCHAR(MAX)
DECLARE @stmt NVARCHAR(MAX)
SET @MDX = dbo.fnCrseReviewDiversityDataStarts(117)
Set @stmt = 'SELECT * FROM OpenQuery(ORA_Link, ''' + REPLACE(@MDX, '''', '''''') + ''')'
PRINT @MDX
EXEC (@stmt)
Please ignore the above SQL Statements. I just used the following sqls directly and it's not working. I found out that months_between function is not working as it works in OracleServer.
SELECT * FROM OpenQuery(ORA_LINK, 'select t2.s_studentreference "Student reference",
to_char(t3.e_start,''YYYY'') "Start",
t1.p_dob,
''31-Aug-''||to_char(t3.e_start,''YYYY'') "StartDate",
months_between(t1.p_dob,''31-Aug-''||to_char(t3.e_start,''YYYY'')) "DifferenceMonths"
from capd_student t2,capd_person t1,capd_moduleenrolment t3
where t2.s_id(+)=t1.p_id and (t3.e_student=t1.p_id) and (t3.e_reference=to_char(1109315))
and t3.e_status = ''L'''
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了答案。
在 Oracle 中,如果我们使用“01-AUG-2010”,它会自动识别为日期。
但是,在传递查询中,我们必须使用 to_date('01-AUG-2010', 'DD-MON-YYYY') 并明确需要告诉这是一个日期。
我不知道为什么,但很有趣。如果您知道答案,请告诉我。非常感谢大家。
I found out the answers.
In Oracle, if we use '01-AUG-2010', it recognizes automatically as a date.
But, in Pass through query, we have to use to_date('01-AUG-2010', 'DD-MON-YYYY') and explicitly needs to tell that this is a date.
I don't know why but Interesting one. If you know an answer, please let me know. Thanks very much all.