1

How can i hold multiline sql query in a shell variable?

SQL='Lets get CREATE TRIGGER STATEMENT'

How to hold it?

8
  • possible duplicate of How can I write a here doc to a file in Bash script? Commented Jul 9, 2015 at 5:51
  • Dear @AvinashRaj did you read my title ? Commented Jul 9, 2015 at 5:54
  • Myfriend take a look at ideone.com/C5JI6d Commented Jul 9, 2015 at 5:56
  • I need it without creating a file Commented Jul 9, 2015 at 5:59
  • newfile is just a variable name. Commented Jul 9, 2015 at 6:01

2 Answers 2

1

This worked well for me

  extract_sql="SELECT *
               FROM TABLE"

To run SQLs with command line tools like wxsubmit or sqlplus

 commandlinesqltool  -options << EOF > /dev/null 2>&1

    SET HEADER OFF

    UPDATE TABLE
    SET    A=1;

EOF
Sign up to request clarification or add additional context in comments.

Comments

0
Declare @sql nvarchar(max);

SET @sql='SELECT *'+char(13) +'FROM table'

Print(@sql);


result: SELECT *
        FROM table

In above query char(13) will hepls to write in next line.

Now @sql variable has two lines.

1 Comment

Are you confusing MySQL with SQL Server? Though I see that the question isn't tagged MySQL, but the chat feeds the SQL to the mysql program.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.