动态声明游标
我需要根据我所处的情况在存储过程中动态创建游标,理想情况如下:
IF (varOrgGroupCode = '') THEN
BEGIN
DECLARE groupCode CURSOR FOR
SELECT `groupcode` FROM `LICENSEKEYS`;
END;
ELSE
BEGIN
DECLARE groupCode CURSOR FOR
SELECT `groupcode` FROM `LICENSEKEYS` WHERE `groupcode` = varOrgGroupCode;
END;
END IF;
上面的代码将导致语法错误。我用谷歌搜索过&有人通过使用临时表来做到这一点。谁能告诉我怎么办?
I need to create Cursors dynamically in stored procedure based on what situation i'm in, the ideal is below:
IF (varOrgGroupCode = '') THEN
BEGIN
DECLARE groupCode CURSOR FOR
SELECT `groupcode` FROM `LICENSEKEYS`;
END;
ELSE
BEGIN
DECLARE groupCode CURSOR FOR
SELECT `groupcode` FROM `LICENSEKEYS` WHERE `groupcode` = varOrgGroupCode;
END;
END IF;
The code above will cause an syntax error. I've googled & someone did it by using temp table. Can anyone tell me how please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在 Google 上找到的内容可能是创建一个临时表,根据您的谓词填充该临时表,然后在游标声明中引用该临时表。
像这样的事情:
Probably the thing you found on Google was to create a temp table, populate that temp table based on your predicate and then reference the temp table in your cursor declaration.
Something like this: