본문 바로가기
MySql

MySQL Workbench에서 세미콜론이 필요하다고 말하는 이유는 무엇입니까?

by 베이스 공부 2020. 11. 20.
반응형

이 코드는 여러 온라인 유효성 검사 테스트를 통과했습니다. 나는 무엇이 잘못되었는지 모른다. CONCAT 함수 뒤에 이미 세미콜론이 있지만 세미콜론이 필요하다는 메시지가 표시됩니다. 그리고 end 에서 문장의 끝을 예상 할 때 외부 입력이라고 말합니다. 무엇을 제공합니까?

create procedure AddColumnUnlessExists(
    IN dbName tinytext,
    IN tableName tinytext,
    IN fieldName tinytext,
    IN fieldDef text)
begin
    IF NOT EXISTS (
        SELECT * FROM information_schema.COLUMNS
        WHERE column_name=fieldName
        and table_name=tableName
        and table_schema=dbName
        )
    THEN
        set @ddl = CONCAT('ALTER TABLE ', dbName, '.', tableName, ' ADD COLUMN ', fieldName, ' ', fieldDef);
        prepare stmt from @ddl;
        execute stmt;
    END IF;
end;

 

해결 방법

 

문제는 DELIMITER 를 사용하지 않는 것입니다.

따라서 다음과 같이 입력하십시오.

DELIMITER //
create procedure AddColumnUnlessExists(
    IN dbName tinytext,
    IN tableName tinytext,
    IN fieldName tinytext,
    IN fieldDef text)
begin
    IF NOT EXISTS (
        SELECT * FROM information_schema.COLUMNS
        WHERE column_name=fieldName
        and table_name=tableName
        and table_schema=dbName
        )
    THEN
        set @ddl = CONCAT('ALTER TABLE ', dbName, '.', tableName, ' ADD COLUMN ', fieldName, ' ', fieldDef);
        prepare stmt from @ddl;
        execute stmt;
    END IF;
end //
DELIMITER ;


mysql 클라이언트 프로그램을 사용하여 세미콜론 문자가 포함 된 저장 프로그램을 정의하면 문제가 발생합니다. 기본적으로 mysql itself recognizes the semicolon as a statement delimiter, so you must redefine the delimiter temporarily to cause mysql to pass the entire 서버에 저장된 프로그램 정의.

mysql 구분자를 재정의하려면 delimiter 명령을 사용하십시오. 그만큼 following example shows how to do this for the dorepeat() procedure just shown. The delimiter is changed to // to enable the entire definition to be passed to the server as a single statement, and then restored to ; before invoking the procedure. This enables the ; delimiter used in the procedure body to be passed through to the mysql 자체에 의해 해석되는 대신 서버.

 

참조 페이지 https://stackoverflow.com/questions/30033987

 

 

반응형

댓글