修改 Oracle 引用游标

发布于 2024-08-07 15:10:50 字数 662 浏览 4 评论 0原文

鉴于:
数据库是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

和我恋爱吧 2024-08-14 15:10:50

创建一个“is_encrypted”函数,该函数返回字符串是否已加密,然后使用 case 语句通过解密函数或直接从表中返回解密值。

select case
       when is_encrypted(secret) = 'Y' then decrypt(secret)
       else secret end as ecrypted_secret
from emp

或者按照问题评论中的建议,只需更改解密函数,这样如果它传递了未加密的字符串,它只返回传递的字符串。

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.

select case
       when is_encrypted(secret) = 'Y' then decrypt(secret)
       else secret end as ecrypted_secret
from emp

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文