Sponsored Content
Top Forums UNIX for Beginners Questions & Answers UNIX variable not working in sql resultset Post 303032859 by Prasad on Monday 25th of March 2019 11:19:50 AM
Old 03-25-2019
UNIX variable not working in sql resultset

Hi,
I am trying to extend unix variable value with mysql resultset. It's working fine in terminal but not working in shell script.

Code:
#!/bin/bash
export prcs_nm=$1
export tbl_nm=$2
export rslt=$(
mysql -sN -u root -proot123 -e "
select sql_query
from retail_db.config where prcs_nm = '$prcs_nm'
"
)
echo "$rslt"

Shell script resultset :
Code:
PRCS_1
products
mysql: [Warning] Using a password on the command line interface can be insecure.
'select \\* from $tbl_nm'

Working fine in terminal :
Code:
~/scripts$ tbl_nm=products
~/scripts$ t_rslt="'select \\* from $tbl_nm'"
~/scripts$ echo $t_rslt
'select \* from products'
~/scripts$ echo "$t_rslt"
'select \* from products'

Could you please let me know why it's not working in shell script?

Thanks,
Prasad.
Moderator's Comments:
Mod Comment Please use code tags

Last edited by vgersh99; 03-25-2019 at 12:46 PM.. Reason: Code tags, please!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sql query variable not exactly unix

I know htis isnt exactly unix.... but hopefully someone can help me or direct me someplace to get help. I can run sql queries in scripts against my informix db using: dbaccess mydb myquery.sql >> sql.output I need to write my script to select based on todays date. Its very... (5 Replies)
Discussion started by: MizzGail
5 Replies

2. Shell Programming and Scripting

How to redirect value from sql select statment to unix variable

Hi, I need to get the value from the table using the sql command and store this value into the unix variable so that i can use this value for furthure use.. Please can any body help me in this regards Thanks & Regards Abdul Hafeez Shaik (17 Replies)
Discussion started by: abdulhafeez
17 Replies

3. Shell Programming and Scripting

Using Unix Variable in a PL/SQL block

Hi, I have a unix varaible called as account which hold values which i want to use in a PL/SQL block in a shell script. This variable value is being used in multiple places in the PL/SQL block and i get an erroe whenenevr is use this varaible with $prompt. Help Urgently (1 Reply)
Discussion started by: sumi_mn
1 Replies

4. Shell Programming and Scripting

I want to get the Unix variable value in the sql stmt

Hi All I have a requirement where in I am stuck. There is a shell script that is being developed by me. It consist of the sql stmt also. I need to export a variable called HOMEPAGE with a value say www.abc.com. and then use this $HOMEPAGE variable in the sql stmt. My ultimate aim is to fetch all... (1 Reply)
Discussion started by: amitsinha
1 Replies

5. Shell Programming and Scripting

Passing a string variable from Unix to Sql Plus

Hi Guys, I am trying to pass a string variable from Unix shell script to sqlplus as a parameter. I have tried using single quotes with the variable name but it does not work. Please help me with it. I am using BASH. My code: Your help is much appreciated. Thanks, shil (2 Replies)
Discussion started by: infintenumbers
2 Replies

6. Shell Programming and Scripting

Redirect output from SQL to unix variable

Hi, I have a requirement to store oracle sqlplus output to some unix variable, count the records and then print the output on the screen. Can you please point me to any sample program for reference purpose. Thanks a lot for your time. (0 Replies)
Discussion started by: bhupinder08
0 Replies

7. Shell Programming and Scripting

UNIX variable to SQL statement

The following is my script : #!/bin/bash echo "please give app_instance_id" read app_instance_id echo "id is $app_instance_id" export app_id=app_instance_id sqlplus -s nnviewer/lookup@//nasolora008.enterprisenet.org:1521/LOAD3 @test.sql<<EOF SPOOL /home/tibco/MCH/Data/qa/raak/name.xls... (4 Replies)
Discussion started by: raakeshr
4 Replies

8. Shell Programming and Scripting

SQL output to UNIX variable

I have a sql statement , i need to assign to a variable in Unix sel count(*) AS num_files from TABLE_A; i need to use "num_files" in unix statements. let me know how to assign unix variable to above num_files (1 Reply)
Discussion started by: nani1984
1 Replies

9. Shell Programming and Scripting

Assign the return value of the SQL to a variable in UNIX

Hi I am new to UNIX. I am trying the below and getting the error. I am trying to assign the variable with the value of the query result. I want this value to use in the next steps. Created UNIX file (Batch.sh) as below #!/bin/ksh sqlplus callidus/callidus4u@attstcal @Batch.sql ... (2 Replies)
Discussion started by: KrishBalu
2 Replies

10. Shell Programming and Scripting

Storing multiple sql queries output into variable by running sql command only once

Hi All, I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise. Eg : Select 'Query 1 output' from dual; Select 'Query 2 output' from dual; I want to... (3 Replies)
Discussion started by: Rokkesh
3 Replies
DBIx::Class::ResultSetColumn(3) 			User Contributed Perl Documentation			   DBIx::Class::ResultSetColumn(3)

NAME
DBIx::Class::ResultSetColumn - helpful methods for messing with a single column of the resultset SYNOPSIS
$rs = $schema->resultset('CD')->search({ artist => 'Tool' }); $rs_column = $rs->get_column('year'); $max_year = $rs_column->max; #returns latest year DESCRIPTION
A convenience class used to perform operations on a specific column of a resultset. METHODS
new my $obj = DBIx::Class::ResultSetColumn->new($rs, $column); Creates a new resultset column object from the resultset and column passed as params. Used internally by "get_column" in DBIx::Class::ResultSet. as_query Arguments: none Return Value: [ $sql, @bind_values ] Returns the SQL query and bind vars associated with the invocant. This is generally used as the RHS for a subquery. next Arguments: none Return Value: $value Returns the next value of the column in the resultset (or "undef" if there is none). Much like "next" in DBIx::Class::ResultSet but just returning the one value. all Arguments: none Return Value: @values Returns all values of the column in the resultset (or "undef" if there are none). Much like "all" in DBIx::Class::ResultSet but returns values rather than result objects. reset Arguments: none Return Value: $self Resets the underlying resultset's cursor, so you can iterate through the elements of the column again. Much like "reset" in DBIx::Class::ResultSet. first Arguments: none Return Value: $value Resets the underlying resultset and returns the next value of the column in the resultset (or "undef" if there is none). Much like "first" in DBIx::Class::ResultSet but just returning the one value. single Arguments: none Return Value: $value Much like "single" in DBIx::Class::ResultSet fetches one and only one column value using the cursor directly. If additional rows are present a warning is issued before discarding the cursor. min Arguments: none Return Value: $lowest_value my $first_year = $year_col->min(); Wrapper for ->func. Returns the lowest value of the column in the resultset (or "undef" if there are none). min_rs Arguments: none Return Value: $resultset my $rs = $year_col->min_rs(); Wrapper for ->func_rs for function MIN(). max Arguments: none Return Value: $highest_value my $last_year = $year_col->max(); Wrapper for ->func. Returns the highest value of the column in the resultset (or "undef" if there are none). max_rs Arguments: none Return Value: $resultset my $rs = $year_col->max_rs(); Wrapper for ->func_rs for function MAX(). sum Arguments: none Return Value: $sum_of_values my $total = $prices_col->sum(); Wrapper for ->func. Returns the sum of all the values in the column of the resultset. Use on varchar-like columns at your own risk. sum_rs Arguments: none Return Value: $resultset my $rs = $year_col->sum_rs(); Wrapper for ->func_rs for function SUM(). func Arguments: $function Return Value: $function_return_value $rs = $schema->resultset("CD")->search({}); $length = $rs->get_column('title')->func('LENGTH'); Runs a query using the function on the column and returns the value. Produces the following SQL: SELECT LENGTH( title ) FROM cd me func_rs Arguments: $function Return Value: $resultset Creates the resultset that "func()" uses to run its query. throw_exception See "throw_exception" in DBIx::Class::Schema for details. AUTHOR AND CONTRIBUTORS
See AUTHOR and CONTRIBUTORS in DBIx::Class LICENSE
You may distribute this code under the same terms as Perl itself. perl v5.18.2 2014-01-23 DBIx::Class::ResultSetColumn(3)
All times are GMT -4. The time now is 09:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy