こんにちは皆さん、ここに簡単なmysqlスクリプトがあります。
delimiter $$
use ta
DROP FUNCTION IF EXISTS bin2uuid;
CREATE FUNCTION bin2uuid(bin BINARY(16)) RETURNS char(36) CHARSET utf8
DETERMINISTIC
BEGIN
DECLARE hex CHAR(32);
IF(bin IS NULL) THEN
RETURN NULL;
ELSE
SET hex = HEX(bin);
RETURN LOWER(CONCAT(LEFT(hex, 8),'-'
,SUBSTR(hex, 9,4),'-'
,SUBSTR(hex,13,4),'-'
,SUBSTR(hex,17,4),'-'
,RIGHT(hex, 12)
));
END IF;
END;
DROP FUNCTION IF EXISTS uuid2bin;
CREATE FUNCTION `uuid2bin`(guid CHAR(36))
RETURNS binary(16)
DETERMINISTIC
BEGIN
IF (guid IS NULL)
THEN
RETURN NULL;
ELSE
SET @newguid = IFNULL(guid, UUID());
RETURN UNHEX(REPLACE(@newguid, '-', ''));
END IF;
END;
DROP FUNCTION IF EXISTS calcAllocTradPartyName;
CREATE FUNCTION calcAllocTradPartyName(vTradeId varchar(36))
RETURNS varchar(200)
BEGIN
DECLARE pTradingPartName varchar(200);
SELECT
IF(tpo.broker = 1,IFNULL(GROUP_CONCAT(DISTINCT IFNULL(tp.symbol,otp.name) SEPARATOR ', '),'TRADAIR'),tpo.name) INTO pTradingPartName
FROM trades t
INNER JOIN orderslogadd o ON t.orderId = o.orderId
INNER JOIN users u ON o.userId = u.guid
LEFT JOIN orgs tpo ON u.orgId = tpo.guid
LEFT JOIN tradesAlloc tra ON t.guid = tra.tradeId
LEFT JOIN tradingparty tp ON tra.tradingpartyId = tp.id
LEFT JOIN orgs otp ON tra.tradingpartyId = otp.guid
WHERE t.guid = uuid2bin(vTradeId);
RETURN pTradingPartName;
END;
$$
app-context.xml
これは、データベースを初期化するmy の一部です。問題は、mysql または TOAD でスクリプトを実行すると正常に動作するが、Spring が実行しようとすると次の例外が発生することです。
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE FUNCTION bin2uuid(bin BINARY(16)) RETURNS char(36) CHARSET utf8 DETER' at line 1
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'delimiter' at line 1
区切り文字なしで実行しようとしましたが、次の$$
例外で失敗します。
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DROP FUNCTION IF EXISTS bin2uuid; CREATE FUNCTION bin2uuid(bin BINARY(16)) RETUR' at line 1