Error Code: 1193. Unknown system variable 'sys_time_in_current_table' - mysql
i am getting following error, while i have tried on google,but didn't find the solution.
Mysql workbench version is 6.2;
Mysql version is 5.6.21.
CREATE DEFINER=`developer`#`%` PROCEDURE `sp_tr069_update_performance_performanceinventory_test`(
in temp_db varchar(256),
in nocout_db varchar(256)
)
BEGIN
declare sys_time_in_current_table int ;
declare sys_time_in_perf_inventory_status int;
set #temporary_query = concat('set sys_time_in_current_table = (select sys_timestamp from ',temp_db,'.','performance_performanceinventory limit 1 )');
PREPARE stmt from #temporary_query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
set #temporary_query1 = concat('set sys_time_in_perf_inventory_status = (select sys_timestamp from ',nocout_db,'.performance_inventorystatus order by id desc limit 1) ;');
PREPARE stmt1 from #temporary_query1;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
set #temporary_query=NULL;
-- set #temporary_query=concat();
-- prepare stmt from ;
select `sys_time_in_current_table`,`sys_time_in_perf_inventory_status`;
IF `sys_time_in_current_table`>`sys_time_in_perf_inventory_status`
THEN
select 1;
set #temporary_query2 =
concat('UPDATE ', nocout_db,'.`performance_inventorystatus` inv_status
INNER JOIN ', temp_db,'.`performance_performanceinventory` perf_inv on
inv_status.device_name=perf_inv.device_name and
inv_status.service_name=perf_inv.service_name and
inv_status.data_source=perf_inv.data_source
SET
inv_status.device_name=perf_inv.`device_name` ,
inv_status.service_name=perf_inv.`service_name` ,
inv_status.machine_name=perf_inv.`machine_name` ,
inv_status.site_name=perf_inv.`site_name` ,
inv_status.ip_address=perf_inv.`ip_address` ,
inv_status.data_source=perf_inv.`data_source` ,
inv_status.severity=perf_inv.`severity` ,
inv_status.current_value=perf_inv.`current_value` ,
inv_status.min_value=perf_inv.`min_value` ,
inv_status.max_value=perf_inv.`max_value` ,
inv_status.avg_value=perf_inv.`avg_value` ,
inv_status.warning_threshold=perf_inv.`warning_threshold` ,
inv_status.critical_threshold=perf_inv.`critical_threshold` ,
inv_status.sys_timestamp=perf_inv.`sys_timestamp` ,
inv_status.check_timestamp=perf_inv.`check_timestamp`;') ;
PREPARE stmt2 from #temporary_query2;
EXECUTE stmt2;
DEALLOCATE PREPARE stmt2;
set #temporary_query3 = concat('INSERT INTO ',nocout_db,'.`performance_inventorystatus`
(
`device_name`,
`service_name`,
`machine_name`,
`site_name`,
`ip_address`,
`data_source`,
`severity`,
`current_value`,
`min_value`,
`max_value`,
`avg_value`,
`warning_threshold`,
`critical_threshold`,
`sys_timestamp`,
`check_timestamp`)
SELECT
`performance_performanceinventory`.`device_name`,
`performance_performanceinventory`.`service_name`,
`performance_performanceinventory`.`machine_name`,
`performance_performanceinventory`.`site_name`,
`performance_performanceinventory`.`ip_address`,
`performance_performanceinventory`.`data_source`,
`performance_performanceinventory`.`severity`,
`performance_performanceinventory`.`current_value`,
`performance_performanceinventory`.`min_value`,
`performance_performanceinventory`.`max_value`,
`performance_performanceinventory`.`avg_value`,
`performance_performanceinventory`.`warning_threshold`,
`performance_performanceinventory`.`critical_threshold`,
`performance_performanceinventory`.`sys_timestamp`,
`performance_performanceinventory`.`check_timestamp`
FROM ', temp_db,'.`performance_performanceinventory`
left join ', nocout_db,'.performance_inventorystatus inv_status on
performance_performanceinventory.device_name=inv_status.device_name and
performance_performanceinventory.service_name=inv_status.service_name and
performance_performanceinventory.data_source=inv_status.data_source
where inv_status.device_name is null ;');
PREPARE stmt3 from #temporary_query3;
EXECUTE stmt3;
DEALLOCATE PREPARE stmt3;
set #temporary_query4 = concat('INSERT INTO', nocout_db,'.`performance_performanceinventory`
(
`device_name`,
`service_name`,
`machine_name`,
`site_name`,
`ip_address`,
`data_source`,
`severity`,
`current_value`,
`min_value`,
`max_value`,
`avg_value`,
`warning_threshold`,
`critical_threshold`,
`sys_timestamp`,
`check_timestamp`)
SELECT
`performance_performanceinventory`.`device_name`,
`performance_performanceinventory`.`service_name`,
`performance_performanceinventory`.`machine_name`,
`performance_performanceinventory`.`site_name`,
`performance_performanceinventory`.`ip_address`,
`performance_performanceinventory`.`data_source`,
`performance_performanceinventory`.`severity`,
`performance_performanceinventory`.`current_value`,
`performance_performanceinventory`.`min_value`,
`performance_performanceinventory`.`max_value`,
`performance_performanceinventory`.`avg_value`,
`performance_performanceinventory`.`warning_threshold`,
`performance_performanceinventory`.`critical_threshold`,
`performance_performanceinventory`.`sys_timestamp`,
`performance_performanceinventory`.`check_timestamp`
FROM ', temp_db,'.`performance_performanceinventory` ;');
PREPARE stmt4 from #temporary_query4;
EXECUTE stmt4;
DEALLOCATE PREPARE stmt4;
set #temporary_query5 = concat('Truncate ', temp_db,'.`performance_performanceinventory`');
PREPARE stmt5 from #temporary_query5;
EXECUTE stmt5;
DEALLOCATE PREPARE stmt5;
END IF;
END
When i execute this stored procedure,then its done ....
but its throwing run time error when i call this procedure....
call nocout_bhutan_testing.sp_tr069_update_performance_performanceinventory_test('tr069_temp_machine_1', 'nocout_bhutan_testing');
Related
mysql stored procedure multiple parameters
I am trying to add multiple dynamic columns in the select statement, (stored procedure) But it's not working at my end, Can you please help me on same. BEGIN SET #col1 = col1;SET #col1 = col2;SET #getID = CONCAT('SELECT ' ,#col1 = col1, #col2 = col2,' FROM',tablename_In,' WHERE `type`= type ORDER BY id DESC LIMIT ?,?'); PREPARE stmt FROM #getID;SET #START =_START; SET #LIMIT = _LIMIT;EXECUTE stmt USING #START, #LIMIT; DEALLOCATE PREPARE stmt; END Also, I have another stored procedure it's also not working with between query: BEGIN SET #getID = CONCAT('SELECT count(id) as co FROM ',tablename_In,' WHERE',est_time,' BETWEEN',start_date,'AND',end_date);PREPARE stmt FROM #getID; EXECUTE stmt; DEALLOCATE PREPARE stmt; END
why does the in paratemers can not be used in PREPARE statement
I am studying mysql. Here is my code of practicing stored procedure. CREATE DEFINER=`raxuser`#`%` PROCEDURE `test`(in fc_frm_date char(5), in fc_to_date char(5)) BEGIN declare frm_date char(5); declare to_date char(5); select fc_frm_date into #frm_date; select fc_to_date into #to_date; select distinct #frm_date, #to_date, fc_frm_date, fc_to_date; set #s = CONCAT('select distinct #frm_date, #to_date, fc_frm_date, fc_to_date;'); PREPARE stmt FROM #s; EXECUTE stmt; DEALLOCATE PREPARE stmt; END When I run it , the first select query get correct while the second one shows error code as Error Code: 1054 Unknown column 'fc_frm_date' in 'field list' I thought the two select queries should be equal but not. Can anyone help to explain? Many thanks.
I think the right way to do this (UNTESTED) is: set #s = CONCAT('select distinct ? , ? , ? , ?;'); PREPARE stmt FROM #s; EXECUTE stmt USING #frm_date, #to_date, fc_frm_date, fc_to_date; DEALLOCATE PREPARE stmt;
Try it: CREATE DEFINER=`raxuser`#`%` PROCEDURE `test`(fc_frm_date char(5), fc_to_date char(5)) BEGIN DECLARE frm_date CHAR(5); DECLARE to_date CHAR(5); SELECT fc_frm_date INTO #frm_date; SELECT fc_to_date INTO #to_date; SELECT fc_frm_date INTO #fc_frm_date; SELECT fc_to_date INTO #fc_to_date; SET #s = 'select distinct #frm_date, #to_date, #fc_frm_date, #fc_to_date'; PREPARE stmt FROM #s; EXECUTE stmt; DEALLOCATE PREPARE stmt; SELECT #s; END
SUBSTRING_INDEX and MySQL Stored Procedures
I am finding it hard to get a MySQL stored procedure to work when I use the SUBSTRING_INDEX and MID and LOCATE functions. The first Select I have works, the other 2 do not. Any help in getting this to work would be awesome. CREATE DEFINER=`root`#`localhost` PROCEDURE `Address`(TBL VARCHAR(50)) BEGIN SET #table_name = TBL; SELECT CONCAT("UPDATE kalo.",#table_name,' SET AD1 = REPLACE(AD1,"."," ")') INTO #SQL; PREPARE stmt FROM #SQL; EXECUTE stmt; DEALLOCATE PREPARE stmt; SELECT CONCAT("UPDATE kalo.",#table_name,' SET STNO = SUBSTRING_INDEX(AD1, ' ', +1)') INTO #SQL; PREPARE stmt FROM #SQL; EXECUTE stmt; DEALLOCATE PREPARE stmt; SELECT CONCAT("UPDATE kalo.",#table_name,' SET STNM = MID(AD1, LOCATE(' ', AD1) + 1)') INTO #SQL; PREPARE stmt FROM #SQL; EXECUTE stmt; DEALLOCATE PREPARE stmt; END
Insert query on procedure
I have a procedure like this set #dt=now(); SET #query = CONCAT('insert into tbl_Name (Name , Created_Date , Created_By) values (?,?,?)'); PREPARE stmt FROM #sql; EXECUTE stmt using #tbl_column_value, #dt, #tbl_user_id; END IF; DEALLOCATE PREPARE stmt; im getting this error java.sql.SQLException: Incorrect arguments to EXECUTE
Correct code improvement
Can somebody look at my code ,because I dont know if its OK or no in MySQL set #max=concat('select max(length(CommentsId))from', table_name); prepare stmt from #max; execute stmt; set #max=concat('UPDATE', table_name, 'SET CommentsId= ',CommentsId * power(10, (#max - length(CommentsId))),' WHERE CommentsId= ', #CommentsId ); prepare stmt from #max; execute stmt;
You need spaces before or after your from, UPDATE, and SET keywords. set #max=concat('select max(length(CommentsId)) from ', table_name); prepare stmt from #max; execute stmt; set #max=concat('UPDATE ', table_name, ' SET CommentsId= ',CommentsId * power(10, (#max - length(CommentsId))),' WHERE CommentsId= ', #CommentsId ); prepare stmt from #max; execute stmt;