2017-01-17 2 views
-2
SELECT DISTINCT 
        clt.id, 
        clt.client_p_email, 
        clt.client_s_email, 
        cus.customer_mail 
from client clt, 
     customers cus 
where clt.id=cus.id 
--My Record is comming bellow 
ID   client_p_email        client_s_email           customer_mail 
-----  ----------------------------  ----------------------------       --------------------------- 
703   [email protected]       [email protected]           [email protected]          
623   [email protected]     [email protected]           [email protected]          
965   [email protected]    [email protected]         [email protected]           
270   [email protected]     [email protected]         [email protected]           
719   [email protected]     [email protected]           [email protected]  

was ich will? Ich möchte alle E-Mails in einer Spalte anzeigen. Aber wenn Sie bemerken, 703 ID muss drei Mal speichern und 623 muss nur zwei Zeit speichern, weil zwei E-Mails gleich sind. und 965 werden einmal gespeichert, weil alle gleich sind. mir bitte vorschlagen, wie kann ich einen anonymen Block erstellen, die Wert speichert ich will
Bitte helfenBenötigen Sie Hilfe zum Speichern von Wert aus drei Spalte

Antwort

0

Sagen Sie Daten in eine Tabelle einfügen möchten, wie:

create table allEmailTable (id number, mail varchar2(100)) 

Vorausgesetzt, dass Sie bereits Ihre Anfrage haben, dass dieses Ergebnis gibt, müssen Sie:

insert into allEmailTable(id, mail) 
with yourQuery(ID, client_p_email, client_s_email, customer_mail) as (
    select 703  , '[email protected]'   ,'[email protected]' , '[email protected]' from dual union all         
    select 623  , '[email protected]'   ,'[email protected]' , '[email protected]' from dual union all          
    select 965  , '[email protected]'  ,'[email protected]', '[email protected]' from dual union all           
    select 270  , '[email protected]'  ,'[email protected]', '[email protected]' from dual union all           
    select 719  , '[email protected]'  ,'[email protected]' , '[email protected]' from dual 
) 
select distinct ID, mail 
from (
     select id, client_p_email as mail from yourQuery UNION 
     select id, client_s_email   from yourQuery UNION 
     select id, customer_mail   from yourQuery 
    ) 

Das Ergebnis:

SQL> select * from allEmailTable; 

     ID MAIL 
---------- -------------------- 
     270 [email protected] 
     270 [email protected] 
     270 [email protected] 
     623 [email protected] 
     623 [email protected] 
     703 [email protected] 
     703 [email protected] 
     703 [email protected] 
     719 [email protected] 
     719 [email protected] 
     719 [email protected] 
     965 [email protected] 

12 rows selected. 

Ihre Anfrage wird sein:

insert into allEmailTable(id, mail) 
with yourQuery(ID, client_p_email, client_s_email, customer_mail) as (
    SELECT DISTINCT 
        clt.id, 
        clt.client_p_email, 
        clt.client_s_email, 
        cus.customer_mail 
    from client clt, 
     customers cus 
where clt.id=cus.id 
) 
select distinct ID, mail 
from (
     select id, client_p_email as mail from yourQuery UNION 
     select id, client_s_email   from yourQuery UNION 
     select id, customer_mail   from yourQuery 
    ) 
+0

Entschuldigung für Missverständnisse, möchte ich mein Ergebnis in new_email_col zu speichern, wie unten: 703 [email protected] eine Zeile wieder 703 [email protected], so 703 wird 3 einfügen – Sohel

+0

Sie brauchen dann ein Update, und nicht eine Auswahl, richtig? – Aleksej

+0

kann ich durch CURSOR einfügen? – Sohel

Verwandte Themen