db2inpe@dmsrvr:~> db2 -tvf test.sqlwith tmp(first,second,third) as ( select substr(ID,locate('.',ID)+1,1), substr(ID,locate('.',ID)+2,1 ), substr(ID,locate('.',ID)+3,1) from test ) select ( case when first='0' and second='0' and third='0' then 'PAREN...
显示全部db2inpe@dmsrvr:~> db2 -tvf test.sql
with tmp(first,second,third) as ( select substr(ID,locate('.',ID)+1,1), substr(ID,locate('.',ID)+2,1 ), substr(ID,locate('.',ID)+3,1) from test ) select ( case when first='0' and second='0' and third='0' then 'PARENT' when first>='A' and first<='Z' and second='0' and third='0' then 'SPLIT' when second>='A' and second<='Z' and third>='1' and third<='9' then 'AUTOSPLIT' when second>='0' and second<='9' and third>='A' and third<='Z' then 'REWORK' else 'UNKNOWN' end ) as lot_type from tmp
LOT_TYPE
---------
0 record(s) selected.
db2inpe@dmsrvr:~> vi test.sql
db2inpe@dmsrvr:~> db2 -tvf test.sql
~ SET CURRENT SCHEMA = "F12SITST"
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0007N The character "~" following "BEGIN-OF-STATEMENT" is not valid.
SQLSTATE=42601
SET CURRENT PATH = "SYSIBM","SYSFUN","SYSPROC","F12SITST"
DB20000I The SQL command completed successfully.
CREATE FUNCTION F12SITST.F_LOT_TYPE (ID VARCHAR(64) ) RETURNS CHARACTER(16)
LANGUAGE SQL NOT DETERMINISTIC READS SQL DATA STATIC DISPATCH CALLED ON
NULL INPUT EXTERNAL ACTION INHERIT SPECIAL REGISTERS BEGIN ATOMIC return
with tmp(first,second,third) as ( select substr(ID,locate('.',ID)+1,1
), substr(ID,locate('.',ID)+2,1 ), substr(ID,locate('.',ID)+3,1
) from test ) select ( case when first='0' and second='0' and
third='0' then 'PARENT' when first>='A' and first<='Z' and second='0' and
third='0' then 'SPLIT' when second>='A' and second<='Z' and third>='1'
and third<='9' then 'AUTOSPLIT' when second>='0' and second<='9' and third>='A'
and third<='Z' then 'REWORK' else 'UNKNOWN' end ) as xx from tmp
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "from tmp" was found following "UNKNOWN' end )
as xx". Expected tokens may include: "
". LINE NUMBER=10.
SQLSTATE=42601
函数里边这么写有问题,貌似不支持吧。最好查infocenter确认下收起