我正在开发一个分区自动化脚本,我需要如下的字符串连接输出。查询的前缀和后缀将被封装在单独的语句中
PARTITION pweek38 VALUES LESS THAN (TO_DAYS('2024-09-22 00:00:00.000000'))
下面是我的代码
SET @q = 'SELECT CONCAT(@query,'' PARTITION '', @partition_name, '' VALUES LESS THAN (TO_DAYS('', @partition_ts, '')'', '')'') INTO @query';
以上语句未在日期时间值之间添加单引号。
SET @q = 'SELECT CONCAT(@query,'' PARTITION '', @partition_name, '' VALUES LESS THAN (TO_DAYS('''''', @partition_ts, '''''')'', '')'') INTO @query';
SELECT @q;
SET @query = '', @partition_name = 'PARTITION_1', @partition_ts = CURRENT_DATE;
PREPARE stmt FROM @q;
EXECUTE stmt;
DROP PREPARE stmt;
SELECT @query;
@q |
---|
SELECT CONCAT(@query,'PARTITION',@partition_name,'值小于(TO_DAYS(''',@partition_ts,''')',')') INTO @query |
@查询 |
---|
PARTITION PARTITION_1 值小于 (TO_DAYS('2024-09-17')) |