我有被声明为这样一个光标(可能):MySQL的游标提取而不声明变量
DECLARE staging_cur CURSOR FOR
SELECT
col1, col2, ......
FROM crawl_db.staging_listing
WHERE is_deleted = FALSE;
我然后取各行,进行一些检查,然后插入一行到另一(生产)数据库
OPEN staging_cur;
the_loop: LOOP
FETCH staging_cur
INTO col1_val, col2_val,.....;
-- perform some checks and some optional inserts
-- for example, if city with given name is not found in production DB, insert it
-- insert into production db
END LOOP the_loop;
原来自己需要声明的变量(col1_val, col2_val ...
)为表staging_listing的(col1, col2....
)每个对应列中。问题是这个表格包含90-100列,并声明所有变量真的很麻烦
看来应该有一个比这更好的方法。有什么方法可以访问游标当前行的列,而无需声明单独的变量来保存列值?
变量的目的是什么? – 2013-03-18 07:47:49
其中一些用于“执行一些检查”步骤。其中大部分用于'insert into production db'步骤。 – arahant 2013-03-18 07:53:34