home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / database / oracle / 2502 < prev    next >
Encoding:
Internet Message Format  |  1992-12-14  |  2.7 KB

  1. Path: sparky!uunet!hayes!fgreene
  2. From: fgreene@hayes.com
  3. Newsgroups: comp.databases.oracle
  4. Subject: Re: SQL*Loader REALLY unique sequences
  5. Message-ID: <6536.2b2c54be@hayes.com>
  6. Date: 14 Dec 92 09:32:46 EDT
  7. References: <1gacpnINNbjl@fmsrl5.srl.ford.com>
  8. Organization: Hayes Microcomputer Products, Norcross, GA
  9. Lines: 61
  10.  
  11. In article <1gacpnINNbjl@fmsrl5.srl.ford.com>, hugh@slee01.srl.ford.com (Hugh Fader) writes:
  12. > I am developing a system which needs to append ASCII data into a table
  13. > and generate a unique identifier for each new row. SQL*Loader has a
  14. > SEQUENCE function which will generate unique sequence number, but the
  15. > numbers will only be unique for a given SQL*Loader session, not for
  16. > the destination table.
  17. > Can anybody offer a way to get SQL*Loader to give me a sequence number
  18. > which is unique for the entire table?
  19. > Thanks in advance.
  20. > --
  21. > Hugh Fader
  22. > Ford Research Laboratory
  23. > hugh@slee01.srl.ford.com
  24. You are on the right track with SEQUENCE, but you need to add the MAX
  25. option.  Assume a target table TEST with columns SEQVAR NUMBER, VAR1 TEXT,
  26. and VAR2 TEXT with values of
  27.     
  28.           SEQVAR   VAR1    VAR2
  29.           ------   ----    ----    
  30.         1    AAA    ZZZ
  31.         2    BBB    YYY
  32.         3    CCC    XXX
  33.  
  34. and an input ASCII table TEST.DAT with contents of
  35.  
  36.         ddd,www
  37.         eee,vvv
  38.  
  39. to load these variables with correct sequence numbers, use
  40.  
  41.     load data
  42.     infile test.dat
  43.     into table test
  44.     append
  45.     fields terminated by ',' optionally enclosed by '"'
  46.     (SEQVAR SEQUENCE(MAX, 1),   -- ***** here is the sequence needed ***
  47.      var1,
  48.          var2)
  49.  
  50. The SEQUENCE(MAX, 1) function attached to SEQVAR variable tells Oracle to scan
  51. the existing table for the maximum value and then increment all successive
  52. entries by 1. Check pg 7-19 of the Utilities manual.
  53.  
  54. The basic function works great.  I have never tested to see what happens if you
  55. have a rejected record.  That is, does Oracle assign a number and then reject
  56. the record leaving a gap, or does it reject the record first leaving some
  57. records without sequence numbers. My guess is that it is position dependent. 
  58.  
  59.   ---------------------------------------------------------------------------
  60.   |      Frank Greene                  |          //////  //////             |
  61.   |      DELPHI SYSTEMS, Inc.          |           ////    ////              |
  62.   |      Telephone [615] 458-6032      |          ////    ////  //////       |
  63.   |      324 Ootsima Way               |         ////    ////    ////        |
  64.   |      Loudon, TN 37774              |        //////  //////  //////       |
  65.   ----------------------------------------------------------------------------
  66.   |         Of course, any opinions or suggestions are strictly my own       |
  67.   ----------------------------------------------------------------------------
  68.