使用 Pro*C 中的 PL/SQL 包游标的最佳方法
我在 PL/SQL 中定义了一个游标,我想知道从 ProC 使用它的最佳方法是什么。通常,对于 ProC 中定义的游标,您会这样做:
EXEC SQL DECLARE curs CURSOR FOR SELECT 1 FROM DUAL;
EXEC SQL OPEN curs;
EXEC SQL FETCH curs INTO :foo;
EXEC SQL CLOSE cusr;
我希望相同(或类似)的语法适用于打包游标。例如,我有一个包 MyPack,带有声明
type MyType is record (X integer);
cursor MyCurs(x in integer) return MyType;
现在我在 Pro*C 代码中有一段相当不令人满意的嵌入式 PL/SQL,它打开游标、执行获取等,因为我无法获得第一个样式的语法来工作。 使用示例
EXEC SQL EXECUTE
DECLARE
XTable is table of MyPack.MyType;
BEGIN
OPEN MyPack.MyCurs(:param);
FETCH MyPack.MyCurs INTO XTable;
CLOSE MyPack.MyCurs;
END;
END-EXEC;
有谁知道是否有更“纯粹”的 Pro*C 方法?
I have a cursor defined in PL/SQL, and I am wondering what the best way to use it from ProC is. Normally for a cursor defined in ProC you would do:
EXEC SQL DECLARE curs CURSOR FOR SELECT 1 FROM DUAL;
EXEC SQL OPEN curs;
EXEC SQL FETCH curs INTO :foo;
EXEC SQL CLOSE cusr;
I was hoping that the same (or similar) syntax would work for a packaged cursor. For example, I have a package MyPack, with a declaration
type MyType is record (X integer);
cursor MyCurs(x in integer) return MyType;
Now I have in my Pro*C code a rather unsatisfying piece of embedded PL/SQL that opens the cursor, does the fetching etc., as I couldn't get the first style of syntax to work.
Using the example
EXEC SQL EXECUTE
DECLARE
XTable is table of MyPack.MyType;
BEGIN
OPEN MyPack.MyCurs(:param);
FETCH MyPack.MyCurs INTO XTable;
CLOSE MyPack.MyCurs;
END;
END-EXEC;
Does anyone know if there is a more "Pure" Pro*C approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它实际上与您的第一个示例没有太大不同,只需确保您的光标定义位于包规范中而不是包主体中。不要“声明”它,只需使用类似以下内容:
数据库对象:
在 pro*c 中:
当然,您正在连接的 oracle 用户需要可以访问该包,等等。如果该包由用户拥有连接,或者有一个同义词,“模式”。 pro*c 调用中不需要。
It actually would not be much different than your first example, just make sure your cursor definition is in the package spec and not the package body. Don't "declare" it and just go with something like:
Database object:
In pro*c:
Of course the package would need to be accessible to the oracle user you are connecting with, etc. If the package is owned by the user connecting, or there is a synonym in place, the "schema." is not required in the pro*c calls.
是的。在谷歌上搜索“REF CURSOR”一词,您应该会看到您想要执行的操作的示例。
Yes. Do a google search on the term REF CURSOR and you should see examples of what you want to do.