[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] [SQL] Betinget INSERT?



Håkan Kvist skrev:
> Jacob Sparre Andersen skrev:

> > Har SQL en kompakt og effektiv formulering af at man gerne vil
> > indsætte en række i en tabel, hvis der ikke allerede findes en
> > række med samme nøgle?
> 
> Om jag förstår din fråga rätt så kan man göra någonting i stil med:
> 
> insert into THE_TABLE(THE_KEY, ...) SELECT(value_to_insert, ...)
>    FROM THE_TABLE
>   WHERE THE_TABLE.THE_KEY NOT IN
>       (
>         SELECT THE_TABLE.THE_KEY
>           FROM THE_TABLE
>          WHERE THE_KEY = value_to_insert);

Tak for vinket.

Det der skulle til var (med en enkelt oracle-særhed i konstruktionen):

   INSERT INTO ASU_Papirtyper (Betegnelse)
   SELECT 'obligation'
   FROM   DUAL
   WHERE  NOT EXISTS (SELECT 'x'
                      FROM   ASU_Papirtyper
                      WHERE  Betegnelse = 'obligation');

»DUAL« er mig bekendt en oracle-særhed.  Det er en tabel der altid
indeholder præcist én række.

Nu mangler jeg bare at pakke det ind i lidt PL/SQL, så konstruktionen
ikke skal gentages alt for mange steder i vores kode.

God fornøjelse,

Jacob
-- 
ACRONYM: A Contrived Reduction Of Nomenclature Yielding Mnemonics


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2009-04-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *