简单的 Oracle 查询:文字与格式字符串不匹配
我想在 Oracle 中执行一个简单的函数。签名定义如下:
CREATE OR REPLACE FUNCTION NewCaseListForValidation
(
p_fromDate in DATE,
p_toDate in DATE,
p_rowCount in INT
)
RETURN
SYS_REFCURSOR
IS
return_value SYS_REFCURSOR;
...
我应该能够执行它:
var rc refcursor
exec :rc := newcaselistforvalidation('2010-01-01','2011-01-01',100);
print :rc
但是当输入“newcaselistforvalidation('2010-01-01','2011-01-01',100)”时,我得到:
ERROR at line 1:
ORA-01861: literal does not match format string
ORA-06512: at line 1
我用谷歌搜索了一下并且看来我无法弄清楚以正确的格式输入日期。谁能帮助我吗?
I want to execute a simple function in Oracle. The signature is defined as follows:
CREATE OR REPLACE FUNCTION NewCaseListForValidation
(
p_fromDate in DATE,
p_toDate in DATE,
p_rowCount in INT
)
RETURN
SYS_REFCURSOR
IS
return_value SYS_REFCURSOR;
...
I should be able to execute it with:
var rc refcursor
exec :rc := newcaselistforvalidation('2010-01-01','2011-01-01',100);
print :rc
But when typing "newcaselistforvalidation('2010-01-01','2011-01-01',100)", I get:
ERROR at line 1:
ORA-01861: literal does not match format string
ORA-06512: at line 1
I googled a bit and it seems I can't figure out to type the date in a correct format. Can anyone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 Oracle 中查询 NLS_PARAMETERS - 然后您将能够看到您的数据库接受的日期格式。
但通常我使用 to_date() 函数:
在英国输入我的日期。
Query NLS_PARAMETERS in Oracle- you will then be able to see what format your DB is accepting dates in.
Typically however i use the to_date() function:
In the UK to input my dates.
to_date() 函数的替代方法是对 DATE 或 TIMESTAMP 文字使用 ANSI 标准格式:
日期和时间始终使用 ISO 规则指定(YYYY-MM-DD 和时间的 24 小时格式)
这也适用于许多其他格式(符合标准)DBMS。
An alternative to the to_date() function is to use the ANSI standard format for DATE or TIMESTAMP literals:
Date and time is always specified using ISO rules (YYYY-MM-DD and 24hour format for time)
This also works on a lot of other (standard compliant) DBMS.
插入 tblDate (dateStart)
值('2013 年 6 月 20 日');
如果将月份整数更改为字符串,“DD-MON-YYYY”将作为有效的数据字符串,而无需在其前面添加 DATE 标识符。
INSERT INTO tblDate (dateStart)
Values ('20-JUN-2013');
If you change month integer into a string 'DD-MON-YYYY' works as a valid data string without having to preface it with the DATE identifier.