修改 Oracle 引用游标
鉴于:
数据库是Oracle 10.2g
我有一个名为 emp 的表。
emp 有一个名为 SECRET 的 VARCHAR2 列。
SECRET 可能包含明文字符串,也可能包含加密字符串,但我可以区分其中一个
一个名为 DECRYPT 的函数已经存在,给定加密的字符串,该函数将返回未加密的字符串。
如何编写一个返回 ref_cursor 的函数,该 ref_cursor 始终在 SECRET 列中包含未加密的字符串?
我在伪代码中寻找的是:
use a cursor to get all the rows of emp
for each row in emp
see if SECRET is encrypted
if yes, decrypt and store the unencrypted value back into SECRET
if no, leave the row untouched
return the cursor as a ref_cursor
本质上我想做的是在返回之前修改引用游标。但是,我认为这是不可能的。
我的第一个想法是建立一个cursor%ROWTYPE的关联数组。没关系。我能做到。但是,我找不到返回关联数组作为引用游标的方法。
关于策略有什么想法吗?
Given:
Oracle 10.2g is the database
I have a table called emp.
emp has a VARCHAR2 column called SECRET.
SECRET might contain a plaintext string, or it might contain an encrypted string, but I can distinguish one from the other
A function called DECRYPT already exists that, given the encrypted string, will return an unencrypted string.
How can I write a function that will return a ref_cursor which always contains an unencrypted string in the SECRET column?
What I'm looking for in pseudocode is:
use a cursor to get all the rows of emp
for each row in emp
see if SECRET is encrypted
if yes, decrypt and store the unencrypted value back into SECRET
if no, leave the row untouched
return the cursor as a ref_cursor
Essentially what I want to do is modify a refcursor before it is returned. However, I don't think that's possible.
My first thought was to build up an associative array of cursor%ROWTYPE. That's fine. I can do that. However, I can't find a way to return an associative array as a refcursor.
Any thoughts on a strategy?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个“is_encrypted”函数,该函数返回字符串是否已加密,然后使用 case 语句通过解密函数或直接从表中返回解密值。
或者按照问题评论中的建议,只需更改解密函数,这样如果它传递了未加密的字符串,它只返回传递的字符串。
Create a "is_encrypted" function which returns if the string is encrypted, then use a case statement to return the decrypted value either via the decrypt function or just straight out of the table.
Or as suggested in question comments, just change the decrypt function so if its passed a non encrypted string, it just returns the string it was passed.