Getting Variable from sqlplus

Multi tool use
Multi tool use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I am trying to get a value from sqlplus like below. However, it does not echo what I want. Here is my script:



#!/bin/ksh
OLDEST_PARTITION='sqlplus / as sysdba << EOF
select PARTITION_NAME
from dba_tab_partitions
where table_name='AUD$' and PARTITION_NAME not like '%FIRST%' and rownum<2
order by PARTITION_NAME asc;
EOF'
echo $OLDEST_PARTITION


And the result is this:



sqlplus / as sysdba << EOF select PARTITION_NAME from dba_tab_partitions where table_name=AUD and PARTITION_NAME not like %FIRST% and rownum<2 order by PARTITION_NAME asc; EOF









share|improve this question



















  • 1




    The first and last single-quote should be a backquote `
    – meuh
    Aug 1 '16 at 12:06














up vote
0
down vote

favorite












I am trying to get a value from sqlplus like below. However, it does not echo what I want. Here is my script:



#!/bin/ksh
OLDEST_PARTITION='sqlplus / as sysdba << EOF
select PARTITION_NAME
from dba_tab_partitions
where table_name='AUD$' and PARTITION_NAME not like '%FIRST%' and rownum<2
order by PARTITION_NAME asc;
EOF'
echo $OLDEST_PARTITION


And the result is this:



sqlplus / as sysdba << EOF select PARTITION_NAME from dba_tab_partitions where table_name=AUD and PARTITION_NAME not like %FIRST% and rownum<2 order by PARTITION_NAME asc; EOF









share|improve this question



















  • 1




    The first and last single-quote should be a backquote `
    – meuh
    Aug 1 '16 at 12:06












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to get a value from sqlplus like below. However, it does not echo what I want. Here is my script:



#!/bin/ksh
OLDEST_PARTITION='sqlplus / as sysdba << EOF
select PARTITION_NAME
from dba_tab_partitions
where table_name='AUD$' and PARTITION_NAME not like '%FIRST%' and rownum<2
order by PARTITION_NAME asc;
EOF'
echo $OLDEST_PARTITION


And the result is this:



sqlplus / as sysdba << EOF select PARTITION_NAME from dba_tab_partitions where table_name=AUD and PARTITION_NAME not like %FIRST% and rownum<2 order by PARTITION_NAME asc; EOF









share|improve this question















I am trying to get a value from sqlplus like below. However, it does not echo what I want. Here is my script:



#!/bin/ksh
OLDEST_PARTITION='sqlplus / as sysdba << EOF
select PARTITION_NAME
from dba_tab_partitions
where table_name='AUD$' and PARTITION_NAME not like '%FIRST%' and rownum<2
order by PARTITION_NAME asc;
EOF'
echo $OLDEST_PARTITION


And the result is this:



sqlplus / as sysdba << EOF select PARTITION_NAME from dba_tab_partitions where table_name=AUD and PARTITION_NAME not like %FIRST% and rownum<2 order by PARTITION_NAME asc; EOF






shell-script scripting






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 2 '16 at 3:50









Jeff Schaller

33.1k849111




33.1k849111










asked Aug 1 '16 at 7:57









john true

1083




1083







  • 1




    The first and last single-quote should be a backquote `
    – meuh
    Aug 1 '16 at 12:06












  • 1




    The first and last single-quote should be a backquote `
    – meuh
    Aug 1 '16 at 12:06







1




1




The first and last single-quote should be a backquote `
– meuh
Aug 1 '16 at 12:06




The first and last single-quote should be a backquote `
– meuh
Aug 1 '16 at 12:06










1 Answer
1






active

oldest

votes

















up vote
0
down vote













As meuh pointed out, unless you copy/pasted the script incorrectly, you have single-quote marks where you need to have backticks. Changing them makes the script into:



#!/bin/ksh
OLDEST_PARTITION=`sqlplus / as sysdba << EOF
select PARTITION_NAME
from dba_tab_partitions
where table_name='AUD$' and PARTITION_NAME not like '%FIRST%' and rownum<2
order by PARTITION_NAME asc;
EOF
`
echo "$OLDEST_PARTITION"


I took care to keep the EOF on its own line, and also quote the OLDEST_PARTITION variable.






share|improve this answer






















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f299545%2fgetting-variable-from-sqlplus%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    As meuh pointed out, unless you copy/pasted the script incorrectly, you have single-quote marks where you need to have backticks. Changing them makes the script into:



    #!/bin/ksh
    OLDEST_PARTITION=`sqlplus / as sysdba << EOF
    select PARTITION_NAME
    from dba_tab_partitions
    where table_name='AUD$' and PARTITION_NAME not like '%FIRST%' and rownum<2
    order by PARTITION_NAME asc;
    EOF
    `
    echo "$OLDEST_PARTITION"


    I took care to keep the EOF on its own line, and also quote the OLDEST_PARTITION variable.






    share|improve this answer


























      up vote
      0
      down vote













      As meuh pointed out, unless you copy/pasted the script incorrectly, you have single-quote marks where you need to have backticks. Changing them makes the script into:



      #!/bin/ksh
      OLDEST_PARTITION=`sqlplus / as sysdba << EOF
      select PARTITION_NAME
      from dba_tab_partitions
      where table_name='AUD$' and PARTITION_NAME not like '%FIRST%' and rownum<2
      order by PARTITION_NAME asc;
      EOF
      `
      echo "$OLDEST_PARTITION"


      I took care to keep the EOF on its own line, and also quote the OLDEST_PARTITION variable.






      share|improve this answer
























        up vote
        0
        down vote










        up vote
        0
        down vote









        As meuh pointed out, unless you copy/pasted the script incorrectly, you have single-quote marks where you need to have backticks. Changing them makes the script into:



        #!/bin/ksh
        OLDEST_PARTITION=`sqlplus / as sysdba << EOF
        select PARTITION_NAME
        from dba_tab_partitions
        where table_name='AUD$' and PARTITION_NAME not like '%FIRST%' and rownum<2
        order by PARTITION_NAME asc;
        EOF
        `
        echo "$OLDEST_PARTITION"


        I took care to keep the EOF on its own line, and also quote the OLDEST_PARTITION variable.






        share|improve this answer














        As meuh pointed out, unless you copy/pasted the script incorrectly, you have single-quote marks where you need to have backticks. Changing them makes the script into:



        #!/bin/ksh
        OLDEST_PARTITION=`sqlplus / as sysdba << EOF
        select PARTITION_NAME
        from dba_tab_partitions
        where table_name='AUD$' and PARTITION_NAME not like '%FIRST%' and rownum<2
        order by PARTITION_NAME asc;
        EOF
        `
        echo "$OLDEST_PARTITION"


        I took care to keep the EOF on its own line, and also quote the OLDEST_PARTITION variable.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 13 '17 at 12:36









        Community♦

        1




        1










        answered Aug 2 '16 at 3:52









        Jeff Schaller

        33.1k849111




        33.1k849111



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f299545%2fgetting-variable-from-sqlplus%23new-answer', 'question_page');

            );

            Post as a guest













































































            6s,AfnRlvWuZAzIiwiTa9K6fq QcJwZ9 4RfFV0wKGe QjYXlVlQBYxbOJmQvBH5vuB P7vzhHk7lYICYzHH JDd
            LkkBJt,EV

            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            How many registers does an x86_64 CPU actually have?

            Displaying single band from multi-band raster using QGIS