Mysql procedure 실행 오류 관련 문의 0 1 2,863

by 이주호 procedure mysql syntax [2016.10.14 14:56:04]


DROP PROCEDURE IF EXISTS board_log_arrange_test;
delimiter;;
CREATE PROCEDURE board_log_arrange_test()
BEGIN

-- setup
DECLARE stmt varchar(2000) default @stmt;

DECLARE partitiontodrop varchar(64);

DECLARE v_max_partno varchar(10);

DECLARE v_max_value int(10);


   select concat('p',(replace(max(partition_name), 'p', '')+1)) into v_max_partno
   from information_schema.partitions as party
   where table_name = 'board_log_test' ;
 
 
   select max(partition_description)+1000000 into v_max_value
   from information_schema.partitions
   where table_name = 'board_log_test';
 
  
   -- Find and drop the first partition in the table.   
   SELECT partition_name
     INTO partitionToDrop
     FROM INFORMATION_SCHEMA.PARTITIONS
     WHERE table_schema='board'
     AND table_name='board_log_test'
     AND partition_ordinal_position=1;
    
   SET @stmt = CONCAT('ALTER TABLE board_log_test DROP PARTITION ' ,  partitionToDrop);
   PREPARE pStmt FROM @stmt;
   EXECUTE pStmt;
   DEALLOCATE PREPARE pStmt;
  
  
   -- Add a new partition using the input date for a value limit.
   SET @stmt = CONCAT('ALTER TABLE board_log_test ADD PARTITION (PARTITION ', v_max_partno, ' VALUES LESS THAN (',v_max_value,')');
   PREPARE pStmt FROM @stmt;
   EXECUTE pStmt;
   DEALLOCATE PREPARE pStmt;
  
   
  
   
-- Cleanup
  SET @stmt = stmt;
END;;
DELIMITER ;

 

 

-------------------------------------------------------------------------------------------------------------------------------

 

위의 프로시져 실행시

Lookup Error - MySQL Database Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1

다음의 에러 메시지가 뜨는데 어디를 교처야 할지 고수님들 도움 부탁드립니다!!!

by 이주호 [2016.10.14 16:30:29]

원인 찾았습니다!!!

 

 -- Add a new partition using the input date for a value limit.
   SET @stmt = CONCAT('ALTER TABLE board_log_test ADD PARTITION (PARTITION ', v_max_partno, ' VALUES LESS THAN (',v_max_value,')');

 

위에서 뒤에 ) 하나가 빠졌었네요

 

-- Add a new partition using the input date for a value limit.
   SET @stmt = CONCAT('ALTER TABLE board_log_test ADD PARTITION (PARTITION ', v_max_partno, ' VALUES LESS THAN (',v_max_value,'))');

 

 

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입