DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: Insert statement from Unix shell script

  1. #1
    Join Date
    Jan 2001
    Posts
    642

    Insert statement from Unix shell script

    Hi,

    I am trying to write a shell script where some
    values are stored in the variables and the same variables
    needs to be stored in the database.

    eg: I have $LOGREAD, $LOGREG, $LOGDIS (all having different values). I want to insert these values from the shell script and so

    I am doing the follwoing

    sqlplus -s gimdev2/gimdev2@cendexpi < insert into control_table
    (dfile,dreg,ddis)
    values
    ($LOGREG,$LOGDIS,$LOGDIS)
    ;
    commit;
    EOF


    This part of the code is giving me SP2-0552 errors, and I am not sure how to make it work from shell script.


    Any suggestions.

    Badrinath
    There is always a better way to do the things.

  2. #2
    Join Date
    Dec 2000
    Location
    Brazil / São Paulo
    Posts
    97
    Try it places script of insert in a separate archive

    sqlplus -s gimdev2/gimdev2@cendexpi @/source/insert.sql
    Márcio de Souza Almeida
    DBA Oracle / SQLServer / PostgreSQL
    Rua Cupa, 139 Apto 85 A
    Penha - São Paulo - SP
    03640-000 - Brasil
    http://www.directory.com.br

  3. #3
    Join Date
    Jan 2001
    Posts
    642
    Hi,

    Thanks, but I know how to do by passing variables to the external .sql file.

    But just wanted to know if I can work in this way when I just invoke the sqlplus and use the shell variables.

    Badrinath
    There is always a better way to do the things.

  4. #4
    Join Date
    Nov 2000
    Location
    Israel
    Posts
    268
    Here's an example of csh script:

    -------------------- Code Starts Here ------------------

    #!/bin/csh -fb
    ######################################

    # Initialize variables
    set LOGREG = ""
    set LOGDIS = ""

    # Collect the variables you want to set
    while ($#argv > 0)
    switch ($argv[1])
    case ...
    endsw
    shift argv
    end


    sqlplus -s gimdev2/gimdev2@cendexpi << EOF
    -- if values inserted are varchar2 type use '$LOGREG' instead of $LOGREG
    insert into control_table(dfile,dreg,ddis) values ($LOGREG,$LOGDIS,$LOGDIS);
    commit;
    EOF

    -------------------- Code Ends Here ------------------

    Ejnoy,
    It is better to ask and appear ignorant, than to remain silent and remain ignorant.

    Oracle OCP DBA 9i,
    C++, Java developer

  5. #5
    Join Date
    Jan 2001
    Posts
    642
    That was my first approach but it came out with
    SP2-0552 errors
    There is always a better way to do the things.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width