How do you SELECT a value from a table into a Unix variable?
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: How do you SELECT a value from a table into a Unix variable?

  1. #1
    Join Date
    Mar 2001
    Posts
    286
    Could you please tell me why the first one works but the second fails?


    tt=`sqlplus -silent dba_mydb/dba_mydb@mydb < set pagesize 0 feedback off verify off heading off echo off
    select count(*) from user_tables;
    --select count(*) from v\$log;
    exit;
    END`
    echo $tt

    tt=`sqlplus -silent dba_mydb/dba_mydb@mydb < set pagesize 0 feedback off verify off heading off echo off
    --select count(*) from user_tables;
    select count(*) from v\$log;
    exit;
    END`
    echo $tt


  2. #2
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,095
    Code:
    tt=`sqlplus -silent dba_mydb/dba_mydb@mydb <
    
    You have to escape the escape...
    Jeff Hunter
    marist89@yahoo.com
    http://marist89.blogspot.com/
    Get Firefox!
    "I pledge to stop eating sharks fin soup and will not do so under any circumstances."

  3. #3
    Join Date
    Mar 2001
    Posts
    286
    Thank you. This works!

    But, why do I need to escape twice?

  4. #4
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,095
    This was my thought process the first time I encountered this:

    If I run this command from the commandline, I would have to escape the $ so it doesn't get intrepreted as a environment variable.

    Since this is inside a script, I have to escape any special characters that will get passed to the command line. Since the \ is a special character, it has to get escaped with \.
    Jeff Hunter
    marist89@yahoo.com
    http://marist89.blogspot.com/
    Get Firefox!
    "I pledge to stop eating sharks fin soup and will not do so under any circumstances."

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