안녕하세요.
어려울때만 찾아서 염치없지만 잘부탁드립니다.
에러내용 : SQL Error [1064] [42000]: 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 '' at line 6
오라클에서 쓰는 translate함수를 mysql에서 여러번 쓰게 되어서 함수를 만들려고 웹서핑을 했는데
아무리 해도 에러만 나옵니다.
부디 고수님 계시면 서포트좀 부탁드립니다.
감사합니다. 꾸벅~^^
ps.
혹시 원인찾는거 안되면 mysql에서 translate 펑션좀 만들어 주시면 안될는지요?
일을 진행 시켜야 하는데 너무 막막해서 그럽니다.
만들려는 함수------------------------------------------
CREATE FUNCTION `translate`(
tar VARCHAR (255),
ori VARCHAR (255),
rpl VARCHAR (255)
) RETURNS VARCHAR (255) CHARSET utf8mb4 DETERMINISTIC BEGIN
DECLARE i INT UNSIGNED DEFAULT 0;
DECLARE cur_char CHAR (1);
DECLARE ori_idx INT UNSIGNED;
DECLARE result VARCHAR (255);
SET result = '';
WHILE i <= length(tar) DO
SET cur_char = mid(tar, i, 1);
SET ori_idx = INSTR(ori, cur_char);
SET result = concat(
result,
REPLACE(
cur_char,
mid(ori, ori_idx, 1),
mid(rpl, ori_idx, 1)
));
SET i = i + 1;
END WHILE;
RETURN result;
END
-------------------------------------------
함수 자체는 문제 없어 보여요~ 함수 만들때 delimiter 를 주고 생성하셔야 해요~ delimiter // CREATE or REPLACE FUNCTION `translate`( tar VARCHAR (255), ori VARCHAR (255), rpl VARCHAR (255) ) RETURNS VARCHAR (255) CHARSET utf8mb4 DETERMINISTIC BEGIN DECLARE i INT UNSIGNED DEFAULT 0; DECLARE cur_char CHAR (1); DECLARE ori_idx INT UNSIGNED; DECLARE result VARCHAR (255); SET result = ''; WHILE i <= length(tar) DO SET cur_char = mid(tar, i, 1); SET ori_idx = INSTR(ori, cur_char); SET result = concat( result, REPLACE( cur_char, mid(ori, ori_idx, 1), mid(rpl, ori_idx, 1) )); SET i = i + 1; END WHILE; RETURN result; END; // delimiter ;
제가 mysql은 처음이라 어느부분이 문젠지 이해를 못하고 있습니다.
그대로 돌렸는데 아래와 같이 에러가 발생합니다.
DBeaver에서 전부 선택해서 ctrl+enter했습니다.
SQL Error [1064] [42000]: 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 'FUNCTION `translate`(
tar VARCHAR (255),
ori VARCHAR (255),
rpl V' at line 1
제가 잘못하는건지 조금 어렵습니다.
delimiter // 따로 실행시킴
CREATE OR REPLACE FUNCTION translate( //그다음 이걸 실행시킴
tar VARCHAR (255),
ori VARCHAR (255),
rpl VARCHAR (255)
) RETURNS VARCHAR (255) CHARSET utf8mb4 DETERMINISTIC begin
DECLARE i INT DEFAULT 1;
DECLARE cur_char CHAR (1);
DECLARE ori_idx INT UNSIGNED;
DECLARE result VARCHAR (255);
SET result = '';
WHILE i <= length(tar) DO
SET cur_char = mid(tar, i, 1);
SET ori_idx = INSTR(ori, cur_char);
SET result = concat(
result,
REPLACE(
cur_char,
mid(ori, ori_idx, 1),
mid(rpl, ori_idx, 1)
));
SET i = i + 1;
END WHILE;
RETURN result;
END;
오류내용
org.jkiss.dbeaver.model.sql.DBSQLException: SQL Error [1064] [42000]: 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 'FUNCTION translate(
tar VARCHAR (255),
ori VARCHAR (255),
rpl VAR' at line 1
at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.executeStatement(JDBCStatementImpl.java:135)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.executeStatement(SQLQueryJob.java:492)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.lambda$0(SQLQueryJob.java:427)
at org.jkiss.dbeaver.model.exec.DBExecUtils.tryExecuteRecover(DBExecUtils.java:170)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.executeSingleQuery(SQLQueryJob.java:419)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.extractData(SQLQueryJob.java:779)
at org.jkiss.dbeaver.ui.editors.sql.SQLEditor$QueryResultsContainer.readData(SQLEditor.java:2966)
at org.jkiss.dbeaver.ui.controls.resultset.ResultSetJobDataRead.lambda$0(ResultSetJobDataRead.java:111)
at org.jkiss.dbeaver.model.exec.DBExecUtils.tryExecuteRecover(DBExecUtils.java:170)
at org.jkiss.dbeaver.ui.controls.resultset.ResultSetJobDataRead.run(ResultSetJobDataRead.java:109)
at org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer$17.run(ResultSetViewer.java:3580)
at org.jkiss.dbeaver.model.runtime.AbstractJob.run(AbstractJob.java:103)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
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 'FUNCTION translate(
tar VARCHAR (255),
ori VARCHAR (255),
rpl VAR' at line 1
at jdk.internal.reflect.GeneratedConstructorAccessor38.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:943)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2483)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2441)
at com.mysql.jdbc.StatementImpl.executeInternal(StatementImpl.java:845)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:745)
at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.execute(JDBCStatementImpl.java:342)
at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.executeStatement(JDBCStatementImpl.java:132)
... 12 more