我是Oracle的新手。表格中包含名字和姓氏(电子邮件为空)。我的问题是用这些要求编写PL / SQL(过程)。
a)firstname的第一个字母与lastname连接(Dan Smilze - - > DSmilze);
b)删除所有重音(ä - - > a,ö - - > o,...);
c)如果出现两封相同的电子邮件,则使用第一个字母的第一个字母而不是一个字母(Dan Smilze - - > DaSmilze);
e)用户名与“@ gmail.com”连接
结果应该是:
FIRSTNAME LASTNAME EMAIL
Dan Smilze DSmilze@gmail.com
Ceo Jürisoo CJurisoo@gmail.com
我的代码是:
CREATE OR REPLACE PROCEDURE merge_email
IS
BEGIN
UPDATE emails set Email = (select CONCAT(substr(firstname,1,1),convert(lastname,'US7ASCII')) from email_lphanvan);
END merge_email;
我知道我的代码不够,不知何故。你能帮我理解这个程序吗?非常感谢你!
答案 0 :(得分:0)
很抱歉,你必须等那么久。它不是最好的解决方案,但它有效:
create table emails (name varchar2(20), surname varchar2(20), email varchar2(40));
insert into emails values ('Jan', 'Kowalski','');
insert into emails values ('Jan', 'Nowak','');
insert into emails values ('Jan', 'Ścigalski','');
insert into emails values ('Stefan', 'Kowalski','');
insert into emails values ('Stefan', 'Kowalski','');
insert into emails values ('Stefan', 'Kowalski','');
insert into emails values ('Józef', 'Błazen','');
insert into emails values ('Jan', 'Nowak','');
commit;
begin
for x in (select rowid, name, surname, row_number() over (partition by name, surname order by name) r from emails) loop
UPDATE emails set Email = convert(substr(x.name,1,x.r),'US7ASCII') || convert(x.surname,'US7ASCII') || '@gmail.com' where rowid = x.rowid;
end loop;
commit;
end;
/
如果表格中有id
,请使用id
代替rowid
。