oracle SQL 存储过程转换日期参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3878072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL Stored Procedure Convert Date Parameter
提问by Jacob
I have a SQL stored procedure which accepts two dates, however when I send them in my open query, Oracle does not like the date format for some reason.
我有一个接受两个日期的 SQL 存储过程,但是当我在打开的查询中发送它们时,Oracle 出于某种原因不喜欢日期格式。
How can I change the dateformat to YYYY-MM-DD
from dd-mm-yyyy
in the stored procedure before sending using it.
在发送使用它之前,如何在存储过程中将日期格式更改为YYYY-MM-DD
from dd-mm-yyyy
。
e.g SET @startdate = CONVERT
例如 SET @startdate = CONVERT
回答by OMG Ponies
Use the TO_DATE functionto convert a string value into an Oracle DATE data type.
使用TO_DATE 函数将字符串值转换为 Oracle DATE 数据类型。
To accept a date string in the format YYYY-MM-DD:
接受格式为 YYYY-MM-DD 的日期字符串:
v_start_date DATE := TO_DATE(v_date_string, 'YYYY-MM-DD');
To accept a date string in the format DD-MM-YYYY:
要接受 DD-MM-YYYY 格式的日期字符串:
v_start_date DATE := TO_DATE(v_date_string, 'DD-MM-YYYY');
回答by PPShein
You can use TO_CHAR
function of Oracle.
您可以使用TO_CHAR
Oracle 的功能。
/*retrieve from query*/
select TO_CHAR(reg_date,'YYYY-MM-DD') REGDATE from Users_TBL
/*Assign to variable*/
regDate := TO_CHAR(reg_date,'YYYY-MM-DD');