2
IBM defines *JUL date format as yy/ddd. It is not commonly used, but is is an available standard format supported on the AS/400. You say you have a string, so the assumption here is that it is stored as CHAR(5), or 5A in DDS.
IBM将* JUL日期格式定义为yy / ddd。它不常用,但是AS / 400支持可用的标准格式。你说你有一个字符串,所以这里的假设是它在DDS中存储为CHAR(5)或5A。
If you column is called jdt, get the right number of digits in your string, in SQL, with:
如果您的列名为jdt,请在SQL中使用以下内容在字符串中获取正确的位数:
RIGHT(('00000' || TRIM(jdt)),5)
Now put the slash in:
现在把斜线放入:
INSERT( RIGHT(('00000'||TRIM(jdt)),5) ,3,0,'/')
DB2/400 can cast this to a real date field, but it will only work properly if you can SET OPTION DATFMT=*JUL
. How to do this from C# on Windows would depend on how you are connecting.
DB2 / 400可以将其转换为实际日期字段,但只有在SET OPTION DATFMT = * JUL时它才能正常工作。如何在Windows上使用C#进行此操作取决于您的连接方式。
Let's suppose you can't find the way to set the date format on your connection.
假设您无法找到在连接上设置日期格式的方法。
Solution: Create a user defined function [UDF] in DB2.
解决方案:在DB2中创建用户定义的函数[UDF]。
First, choose an appropriate library to store the function in, and set that as your current library. In OS/400 CL, CHGCURLIB yourlib
, or in SQL, SET SCHEMA = yourlib
. Thus by default anything you create will go into this library.
首先,选择适当的库来存储函数,并将其设置为当前库。在OS / 400 CL,CHGCURLIB yourlib或SQL中,SET SCHEMA = yourlib。因此,默认情况下,您创建的任何内容都将进入此库。
I recommend storing the SQL definition for your UDF in a source member. (Ask if unfamiliar) You can execute the source with the RUNSQLSTM
command.
我建议将UDF的SQL定义存储在源成员中。 (询问是否不熟悉)您可以使用RUNSQLSTM命令执行源。
Your function definition could look something like this:
您的函数定义可能如下所示:
CREATE FUNCTION CvtJul2Date( jdtin char(5) ) RETURNS DATE
LANGUAGE SQL
SPECIFIC CVTJUL2DT
DETERMINISTIC NO EXTERNAL ACTION
CONTAINS SQL
RETURNS NULL ON NULL INPUT
SET OPTION DATFMT = *JUL
BEGIN
RETURN(
date( insert( right(('00000'||trim(jdtin)),5) ,3,0,'/') )
);
END
The *JUL option is scoped to the UDF. Any SQL query that runs on the AS/400 should be able to do this conversion, regardless of the DATFMT of the job (assuming you have put this function in a library which is on that job's library list).
* JUL选项的作用域是UDF。无论作业的DATFMT如何(假设您已将此函数放在该作业的库列表中的库中),在AS / 400上运行的任何SQL查询都应该能够执行此转换。