Leandro Toshio Takeda
Leandro Toshio Takeda

Reputation: 1639

How to return just the value with sql inside shell script?

The code below is returning:

EMAIL -------------------------------------------------------------------------------- [email protected]

case "$type" in

                2)
                echo "Type is outbound: $type"
                        contact=$(sqlplus -s ${SQLPLUS_INFO} <<EOF
                        SELECT email FROM table WHERE email = 'x';
                        exit
                        EOF)
                        echo
                        echo $contact
                        echo
                ;;

                1)
                echo "Type is inbound: $type"
                ;;
        esac

But I just would like:

EMAIL -------------------------------------------------------------------------------- [email protected]

Any help please?

Upvotes: 1

Views: 2466

Answers (2)

glenn jackman
glenn jackman

Reputation: 247082

The sqlplus command set pagesize 0 turns off column headers and other pagination stuff.

case "$type" in
    2)  echo "Type is outbound: $type"
        contact=$(sqlplus -s ${SQLPLUS_INFO} <<EOF
            set pagesize 0
            SELECT email FROM table WHERE email = 'x';
            exit
EOF
        )
        printf "\n%s\n\n" "$contact"
    ;;

This page is a useful reference: http://ss64.com/ora/syntax.html

Upvotes: 2

Renato Todorov
Renato Todorov

Reputation: 560

Problem is that you put ) after the EOF statement.

EOF should always come alone!

Fix your script by putting the ) on a new line.

...
exit
EOF
)
echo
...

Upvotes: 1

Related Questions