Start a new topic

Questions using delimiters

[This topic is migrated from our old forums. The original author name has been removed]

Hi DBVis team, I am a total sql beginner and my developer is not using dbvisualizer. I received an sql statement from the developer which I would like to execute in dbvis. I have tried a few things to change the delimiter but do not know how. I always receive error messages. Here is the first part of the sql script. How do I set the delimiters in the tools section of dbvisualizer that it executes correctly: What exactly do I use as: 1) SQL Statement Delimiter 1 2) SQL Statement Delimiter 2 3) Allow "go" as Delimiter 4) Beginn Identifier 5) End Identifier Thank you wtmnn DELIMITER $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `all_signal_ts_date_symbol_signal`(IN _date_ts BIGINT, IN _symbol_id INT, IN _signal_id INT) BEGIN SELECT * FROM signals_ts WHERE date_ts = _date_ts AND symbol_id = _symbol_id AND signal_id = _signal_id; END$$ DELIMITER ; DELIMITER $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `atest`(IN in_date datetime, IN in_date_ts long, IN in_portfolio_id int, IN in_nav_start int) BEGIN DECLARE differencePnL double; DECLARE sumPnL double; DECLARE sumTodayPositionsPnL double; DECLARE netExposure double; DECLARE grossExposure double; DECLARE differenceNetExposure double; DECLARE differenceGrossExposure double; DECLARE navCurrent double; DECLARE barPnL double; DECLARE differenceNavCurrent double; DECLARE differenceBarPnL double; DECLARE EXIT HANDLER FOR 1213 BEGIN ROLLBACK; call atest(in_date, in_date_ts, in_portfolio_id, in_nav_start); END; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; INSERT INTO errors (message, date, dateTS, procedureName, errorType) VALUES(concat('SQLEXCEPTION ; in_date: ', in_date, ' ; in_date_ts: ', in_date_ts, ' ; in_portfolio_id: ', in_portfolio_id, ' ; in_nav_start: ', in_nav_start), NOW(), UNIX_TIMESTAMP(NOW()), 'atest', 1); END; DECLARE EXIT HANDLER FOR SQLWARNING BEGIN ROLLBACK; INSERT INTO errors (message, date, dateTS, procedureName, errorType) VALUES(concat('SQLWARNING ; in_date: ', in_date, ' ; in_date_ts: ', in_date_ts, ' ; in_portfolio_id: ', in_portfolio_id, ' ; in_nav_start: ', in_nav_start), NOW(), UNIX_TIMESTAMP(NOW()), 'atest', 2); END; START TRANSACTION; SET sumTodayPositionsPnL = IFNULL((SELECT SUM(unrealizedPnL) FROM portfolio_positions_sql AS pps inner join (select max(date_ts) as date_ts, symbol_id from portfolio_positions_sql WHERE portfolio_id = in_portfolio_id and date_ts <= in_date_ts group by symbol_id) AS dis ON dis.symbol_id = pps.symbol_id and dis.date_ts = pps.date_ts WHERE portfolio_id = in_portfolio_id), 0); SET sumPnL = sumTodayPositionsPnL; SET navCurrent = in_nav_start + sumPnL; SET barPnL = navCurrent - IFNULL((SELECT strat_nav_current FROM portfolio_ts_sql WHERE date_ts < in_date_ts AND portfolio_id = in_portfolio_id ORDER BY date_ts DESC LIMIT 1), 0); SET netExposure = IFNULL((select SUM(market_value) from portfolio_positions_sql as pps inner join (select max(date_ts) as date_ts, symbol_id from portfolio_positions_sql where portfolio_id = in_portfolio_id and date_ts <= in_date_ts group by symbol_id) as dis on dis.symbol_id = pps.symbol_id and dis.date_ts = pps.date_ts where portfolio_id = in_portfolio_id), 0); SET grossExposure = IFNULL((select SUM(ABS(market_value)) from portfolio_positions_sql as pps inner join (select max(date_ts) as date_ts, symbol_id from portfolio_positions_sql where portfolio_id = in_portfolio_id and date_ts <= in_date_ts group by symbol_id) as dis on dis.symbol_id = pps.symbol_id and dis.date_ts = pps.date_ts where portfolio_id = in_portfolio_id), 0); IF ((SELECT COUNT(*) FROM portfolio_ts_sql where date_ts = in_date_ts AND portfolio_id = in_portfolio_id) > 0) THEN SET differencePnL = sumPnL - IFNULL((SELECT strat_pnlcum FROM portfolio_ts_sql WHERE date_ts = in_date_ts AND portfolio_id = in_portfolio_id), 0); SET differenceNetExposure = netExposure - IFNULL((SELECT strat_expnet FROM portfolio_ts_sql WHERE date_ts = in_date_ts AND portfolio_id = in_portfolio_id), 0); SET differenceGrossExposure = grossExposure - IFNULL((SELECT strat_expgross FROM portfolio_ts_sql WHERE date_ts = in_date_ts AND portfolio_id = in_portfolio_id), 0); SET differenceNavCurrent = navCurrent - IFNULL((SELECT strat_nav_current FROM portfolio_ts_sql WHERE date_ts = in_date_ts AND portfolio_id = in_portfolio_id), navCurrent); SET differenceBarPnL = barPnL - IFNULL((SELECT strat_pnlbar FROM portfolio_ts_sql WHERE date_ts = in_date_ts AND portfolio_id = in_portfolio_id), 0); UPDATE portfolio_ts_sql SET strat_pnlcum = sumPnL, strat_expgross = grossExposure, strat_expnet = netExposure, strat_pnlbar = barPnL, strat_nav_current = navCurrent WHERE date_ts = in_date_ts AND portfolio_id = in_portfolio_id; UPDATE portfolio_ts_sql SET strat_pnlcum = strat_pnlcum + differencePnL, strat_expgross = strat_expgross + differenceGrossExposure, strat_expnet = strat_expnet + differenceNetExposure, strat_nav_current = strat_nav_current + differenceNavCurrent WHERE date_ts > in_date_ts AND portfolio_id = in_portfolio_id; ELSE INSERT INTO portfolio_ts_sql (portfolio_id, date, date_ts, created_date, created_date_ts, last_updated_date, last_updated_date_ts, strat_pnlcum, strat_expgross, strat_expnet, strat_nav_current, strat_pnlbar, strat_nav_start) VALUES(in_portfolio_id, in_date, in_date_ts, in_date, in_date_ts, in_date, in_date_ts, sumPnL, grossExposure, netExposure, navCurrent, barPnL, in_nav_start); UPDATE portfolio_ts_sql SET strat_pnlcum = strat_pnlcum + sumTodayPositionsPnL, strat_expgross = strat_expgross + grossExposure, strat_expnet = strat_expnet + netExposure, strat_pnlbar = strat_pnlbar + barPnL, strat_nav_current = strat_nav_current + sumPnL WHERE date_ts > in_date_ts AND portfolio_id = in_portfolio_id; END IF; COMMIT; END$$ DELIMITER ;
1 Comment

[This reply is migrated from our old forums.]

Re: Questions using delimiters
Hi, I suggest you check the following for more information about how to execute blocks of SQL code: http://confluence.dbvis.com/display/UG91/Executing+Complex+Statements Basically you should replace: DELIMITER $$ with @delimiter $$; and DELIMITER ; with @delimiter ;$$ Regards Roger