【问题标题】:oracle sql cursor update an email domain name using an email domain nameoracle sql cursor 使用邮件域名更新邮件域名
【发布时间】:2020-02-20 00:41:09
【问题描述】:

我想给一个域名换一个新的域名。该过程将传递两个字符串。 不使用主键但使用电子邮件 执行程序('gmail.com', 'hotmail.com');

数据库中所有带有“Gmail.com”的电子邮件都将更改为“Hotmail.com”的新域名。 这是我的代码。

我在调用 PR_Q3 时遇到错误的参数数量或类型错误

create procedure PR_Q3
is P_NewEamil varchar2(50); P_OldEmail varchar2(50);
cursor E_info is select Email_Address from Broker where P_OldEmail = Email_Address
for update of Email_Address;
begin 
open E_info;
fetch E_info into P_NewEamil;
while E_info%found loop 
if(P_NewEamil like '%.com') then 
update Broker set Email_Address = P_NewEamil where Email_Address= P_OldEmail;
else 

 end if;
end loop;
close E_info;

 end PR_Q3;

【问题讨论】:

  • 您没有显示正在调用该过程的调用。你知道,你可以用一条更新语句来做到这一点,不需要游标/循环

标签: sql oracle sql-update cursor


【解决方案1】:

您的程序应如下所示:

create procedure PR_Q3(p_oldemail in varchar2,
                       p_newemail in varchar2)
As
Begin

UPDATE BROKER
SET
    EMAIL_ADDRESS = REPLACE(EMAIL_ADDRESS, p_oldemail, p_newemail)
WHERE
    REGEXP_LIKE ( EMAIL_ADDRESS,'.*@'|| p_oldemail|| '$' );

Commit;

End;
/

要调用此过程,您需要传递两个域,如下所示:

Begin
Pr_q3('gmail.com', 'hotmail.com');
End;
/

干杯!!

【讨论】:

  • 以及如何确保所有变体(大写或小写)
  • 尝试学习,上下函数。您将能够在此解决方案中添加该功能
猜你喜欢
  • 2010-12-21
  • 1970-01-01
  • 2016-05-12
  • 2012-05-13
  • 1970-01-01
  • 1970-01-01
  • 2014-06-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多