home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume22 / oraperl / patch02 / mkdb.pl < prev    next >
Encoding:
Perl Script  |  1991-08-25  |  1.4 KB  |  74 lines

  1. #!./oraperl
  2. #
  3. # mkdb.pl
  4. #
  5. # Sample oraperl program to create a new database and load data into it.
  6. #
  7. # Author:    Kevin Stock
  8. # Date:        5th August 1991
  9. #
  10.  
  11. # let's see what oraperl is doing when it executes this
  12.  
  13. $ora_debug = 136;
  14.  
  15. $CREATE = "create table tryit (name char(10), ext number(3))";
  16. $INSERT = "insert into tryit values (:1, :2)";
  17. $LIST    = "select * from tryit order by name";
  18. $DROP    = "drop table tryit";
  19.  
  20. format top =
  21.        Name         Ext
  22.        ====         ===
  23. .
  24.  
  25. format STDOUT =
  26.        @<<<<<<<<<   @>>
  27.        $name,       $ext
  28. .
  29.  
  30. die ("You should use oraperl, not perl\n") unless defined &ora_login;
  31.  
  32. # create the database
  33.  
  34. $lda = &ora_login("t", "kstock", "kstock")    || die $ora_errstr;
  35. $csr = &ora_open($lda, $CREATE)            || die $ora_errstr;
  36. do ora_close($csr)                || die $ora_errstr;
  37.  
  38. # put some data into it
  39.  
  40. $csr = &ora_open($lda, $INSERT)            || die $ora_errstr;
  41. while (<DATA>)
  42. {
  43.     m/([a-z]+):([0-9]+)/;
  44.     do ora_bind($csr, $1, $2);
  45. }
  46. do ora_close($csr)                || die $ora_errstr;
  47.  
  48. # list the result
  49.  
  50. $csr = &ora_open($lda, $LIST)            || die $ora_errstr;
  51. while (($name, $ext) = &ora_fetch($csr))
  52. {
  53.     write;
  54. }
  55. do ora_close($csr)                || die $ora_errstr;
  56.  
  57. # remove the database
  58.  
  59. $csr = &ora_open($lda, $DROP)            || die $ora_errstr;
  60. do ora_close($csr)                || die $ora_errstr;
  61. do ora_logoff($lda)                || die $ora_errstr;
  62. __END__
  63. david:225
  64. angela:208
  65. bruno:302
  66. albert:294
  67. julia:292
  68. alison:206
  69. arnold:305
  70. larry:424
  71. catherine:201
  72. randall:306
  73. susan:307
  74.