Results 1 to 6 of 6

Thread: parameterized sql file as input to nzsql

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    4

    Question parameterized sql file as input to nzsql

    Hi All,

    I want to a pass parameterized sql file as input to nzsql. HOw to do that?

    Ex:-
    query.sql
    --------------
    Select * from tablename where column_name like '&1';



    unixscript.sh
    ------------

    colval='abc';
    nzsql -h hostname -d database -u username -pw pass < ./query.sql $colval


    thus the query which should be processed will be like
    Select * from tablename where column_name like 'abc';


    Pblm being nzsql is trying to execute the content of the query.sql i.e,
    Select * from tablename where column_name like '&1';
    and as there are no records having value in column_name as '&1' its returning null result

    Please help me in this regard
    Thanks in advance

  2. #2
    Senior Member vijay's Avatar
    Join Date
    May 2012
    Location
    Hyderabad
    Posts
    515
    Try using the -v option of nzsql command.

    -v name=value

    Sets the nzsql variable name to the specified value. You can specify one or more -v options to set several options, for example: nzsql -v HISTSIZE=600 -v USER=user1 -v PASSWORD=password

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Quote Originally Posted by vijay View Post
    Try using the -v option of nzsql command.

    -v name=value

    Sets the nzsql variable name to the specified value. You can specify one or more -v options to set several options, for example: nzsql -v HISTSIZE=600 -v USER=user1 -v PASSWORD=password

    Hi Vijay,

    Thanks for the response. But i am still facing trouble.

    temp.sql
    ---------
    select * from TABLE_NAME


    unixscript.sh
    ------------

    nzsql -h hostname -d dbname -u username -pw pass -v TABLE_NAME=tablename < temp.sql


    But i am not getting desired output.

    Can you please correct me where i am going wrong.

  4. #4
    Senior Member vijay's Avatar
    Join Date
    May 2012
    Location
    Hyderabad
    Posts
    515
    You have to specify a colon before the variable name. An example is shown below:

    temp.sql file:

    Code:
    select * from :TABLENAME
    nzsql command:

    Code:
    nzsql -h hostname -d dbname -u username -pw pass -v TABLENAME=tb -f temp.sql

  5. #5
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Thanks Vijay... Its working.

  6. #6
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Thanks Vijay.

    Its working

Similar Threads

  1. Replies: 0
    Last Post: 11-15-2013, 01:00 AM
  2. Replies: 0
    Last Post: 10-23-2013, 01:20 PM
  3. Replies: 0
    Last Post: 10-14-2013, 10:21 PM
  4. Replies: 0
    Last Post: 09-27-2013, 06:11 PM
  5. Replies: 0
    Last Post: 09-17-2013, 06:52 PM

Tags for this Thread

Bookmarks

Posting Permissions

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