Sponsored Content
Full Discussion: Result set into an array
Top Forums Shell Programming and Scripting Result set into an array Post 302453166 by solo123 on Tuesday 14th of September 2010 08:21:15 AM
Old 09-14-2010
Result set into an array

Hi,

I have an issue with the result set. I wanted to run db2 query against db2 server in unix environment using perl script. I wanted to get the result set into an array.

$db=<<DB_Name>>

connect to $db
get connection state

this is my query = SELECT DISTINCT 'R' FROM SYSCAT.TABAUTH;

any help really appreciated..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Prase a file and stored the result to an array

Dear all , I have a file whose content has the following format: jboss.web:type=ThreadPool,name=AAAA jboss.web:type=ThreadPool,name=BBBB How can I parse this file to get the value of the name of each line (AAAA , BBBB) and store the result to an array ? (array = AAAA , array = BBBB).... (4 Replies)
Discussion started by: youareapkman
4 Replies

2. Shell Programming and Scripting

Prase a file and store and result to an array

Dear all, I have a file having the following formats: ThreadFail=Web1=1234 ThreadFail=Web2=2345 ThreadFail=Web3=12 ConnectionFail=DB1=11 ConnectionFail=DB2=22 The number of lines will be different from every time . How can I parse the file and store the result to an a array inside... (6 Replies)
Discussion started by: youareapkman
6 Replies

3. Programming

Send email for each row in a result set

I have SQL giving me output of disabled ids in the system every day. I can send on email for this disabled user list. But I want to send one email for every disabled user or for every row. thank you for your help. Kyle (2 Replies)
Discussion started by: s1a2m3
2 Replies

4. Shell Programming and Scripting

How to get and process mysql result set in shell script

Hi All, I am in a problem here is the description, Actually in my shell script i am firing a mysql query which returns multiple records and i have to process each record one by one. So could any one please suggest me how to solve my problem? Thanks in Advance Ashok Sharma (4 Replies)
Discussion started by: ashok1979
4 Replies

5. Shell Programming and Scripting

If the grep command returns any result set

my intension is to use a grep command inside the shell script and if any row is returned or not.. depending on the resultset i have to code on further. how to check this i mean.. could anyone help me out with the if condition how to use it here !! (4 Replies)
Discussion started by: gotam
4 Replies

6. Shell Programming and Scripting

How do i access sybase using isql and how do i get result set in perl script?

Hi, How do i get result set in perl script using isql while connecting sybase server. I have a perl script which connected to sybase and get the result set. but i wanted to get the result set. How do i get the result set in perl script not unix shell script.. $server ="ServerName"; open... (1 Reply)
Discussion started by: solo123
1 Replies

7. Shell Programming and Scripting

how to output the array result into a matrix

I have a file like this: ASSPASVFETQY,hTRBV12-4,hTRBJ2-5,2 ASSPASTGGDYGYT,hTRBV18,hTRBJ1-2,2 ASSPASGDGYT,hTRBV5-1,hTRBJ1-2,2 ASSPASFPEDTQY,hTRBV27,hTRBJ2-3,2 ASSPARVNYGYT,hTRBV5-1,hTRBJ1-2,2 ASSPARTSGGLNEQF,hTRBV6-4,hTRBJ2-1,2 ASSPARQSYNEQF,hTRBV11-1,hTRBJ2-1,2... (3 Replies)
Discussion started by: xshang
3 Replies

8. Shell Programming and Scripting

ksh : Building an array based on condition result

I want to build an Errorlog. I would like to build an array as I move through the if statements and print the array once all error conditions have been defined. The results need to be comma delimited. tsver will be static "1.9.6(2)" other vars $prit $lt $rt can have the same or a different... (1 Reply)
Discussion started by: popeye
1 Replies

9. UNIX for Dummies Questions & Answers

Find commmand returning search path with the result set

OS Platform : Oracle Linux 6.5 We are creating a shell script to purge old log files . It uses find command with rm in it. The syntax is find <Path of Log Directory> -exec rm -fr {} \; Example: find /tmp/test3 -exec rm -fr {} \; For rm command , we use -r option to... (4 Replies)
Discussion started by: kraljic
4 Replies

10. UNIX for Beginners Questions & Answers

Need to filter the result set within 2 time frame

my sample file is like this $cat onefile 05/21/18 13:10:07 ABRT US1CPDAY Status 1 05/21/18 21:18:54 ABRT DailyBackup_VFFPRDAPENTL01 Status 6 05/21/18 21:26:24 ABRT DailyBackup_VFFPRDAPENTL02 Status 6 05/21/18 21:57:36 ABRT DailyBackup_vm-ea1ffpreng01 Status 6... (7 Replies)
Discussion started by: gotamp
7 Replies
MongoDB::Examples(3pm)					User Contributed Perl Documentation				    MongoDB::Examples(3pm)

NAME
MongoDB::Examples - Some examples of MongoDB syntax MAPPING SQL TO MONGODB
For developers familiar with SQL, the following chart should help you see how many common SQL queries could be expressed in MongoDB. These are Perl-specific examples of translating SQL queries to MongoDB's query language. To see the JavaScript (or other languages') mappings, see <http://dochub.mongodb.org/core/sqlToMongo>. "CREATE TABLE USERS (a Number, b Number)" Implicit, can be done explicitly. "INSERT INTO USERS VALUES(1,1)" $db->users->insert({a => 1, b => 1}); "SELECT a,b FROM users" $db->users->find({}, {a => 1, b => 1}); "SELECT * FROM users" $db->users->find; "SELECT * FROM users WHERE age=33" $db->users->find({age => 33}) "SELECT a,b FROM users WHERE age=33" $db->users->find({age => 33}, {a => 1, b => 1}); "SELECT * FROM users WHERE age=33 ORDER BY name" $db->users->find({age => 33})->sort({name => 1}); "<SELECT * FROM users WHERE age"33>> $db->users->find({age => {'$gt' => 33}}) "<SELECT * FROM users WHERE age<33"> $db->users->find({age => {'$lt' => 33}}) "SELECT * FROM users WHERE name LIKE "%Joe%"" $db->users->find({name => qr/Joe/}); "SELECT * FROM users WHERE name LIKE "Joe%"" $db->users->find({name => qr/^Joe/}); "<SELECT * FROM users WHERE age"33 AND age<=40>> $db->users->find({age => {'$gt' => 33, '$lte' => 40}}); "SELECT * FROM users ORDER BY name DESC" $db->users->find->sort({name => -1}); "CREATE INDEX myindexname ON users(name)" $db->users->ensure_index({name => 1}); "CREATE INDEX myindexname ON users(name,ts DESC)" $db->users->ensure_index(Tie::IxHash->new(name => 1, ts => -1)); "SELECT * FROM users WHERE a=1 and b='q'" $db->users->find({a => 1, b => "q"}); "SELECT * FROM users LIMIT 10 SKIP 20" $db->users->find->limit(10)->skip(20); "SELECT * FROM users WHERE a=1 or b=2" $db->users->find({'$or' => [{a => 1}, {b => 2}]}); "SELECT * FROM users LIMIT 1" $db->users->find->limit(1); "EXPLAIN SELECT * FROM users WHERE z=3" $db->users->find({z => 3})->explain; "SELECT DISTINCT last_name FROM users" $db->run_command({distinct => "users", key => "last_name"}); "SELECT COUNT(*y) FROM users" $db->users->count; "<SELECT COUNT(*y) FROM users where age " 30>> $db->users->find({"age" => {'$gt' => 30}})->count; "SELECT COUNT(age) from users" $db->users->find({age => {'$exists' => 1}})->count; "UPDATE users SET a=1 WHERE b='q'" $db->users->update({b => "q"}, {'$set' => {a => 1}}); "UPDATE users SET a=a+2 WHERE b='q'" $db->users->update({b => "q"}, {'$inc' => {a => 2}}); "DELETE FROM users WHERE z="abc"" $db->users->remove({z => "abc"}); DATABASE COMMANDS
Distinct The distinct command returns all values for a given key in a collection. For example, suppose we had a collection with the following documents ("_id" value ignored): { 'name' => 'a', code => 1 } { 'name' => 'b', code => 1 } { 'name' => 'c', code => 2 } { 'name' => 'd', code => "3" } If we wanted to see all of values in the "code" field, we could run: my $result = $db->run_command([ "distinct" => "collection_name", "key" => "code", "query" => {} ]); Notice that the arguments are in an array, to ensure that their order is preserved. You could also use a Tie::IxHash. "query" is an optional argument, which can be used to only run "distinct" on specific documents. It takes a hash (or Tie::IxHash or array) in the same form as "find($query)" in MongoDB::Collection. Running "distinct" on the above collection would give you: { 'ok' => '1', 'values' => [ 1, 2, "3" ] }; Find-and-modify The find-and-modify command is similar to update (or remove), but it will return the modified document. It can be useful for implementing queues or locks. For example, suppose we had a list of things to do, and we wanted to remove the highest-priority item for processing. We could do a "find" in MongoDB::Collection and then a "remove" in MongoDB::Collection, but that wouldn't be atomic (a write could occur between the query and the remove). Instead, we can use find and modify. my $next_task = $db->run_command({ findAndModify => "todo", sort => {priority => -1}, remove => 1 }); This will atomically find and pop the next-highest-priority task. See <http://www.mongodb.org/display/DOCS/findAndModify+Command> for more details on find-and-modify. Group The group command is similar to "GROUP BY" in SQL. You can use the "run_command" in MongoDB::Database method to perform group-bys with MongoDB. For example, suppose we have a number of local businesses stored in a "business" collection. If we wanted to find the number of coffeeshops in each neighborhood, we could do: my $reduce = <<REDUCE; function(doc, prev) { for (var t in doc.tags) { if (doc.tags[t] == "coffeeshop") { prev["num coffeeshops"]++; break; } } } REDUCE my $result = $db->run_command({group => { 'ns' => "business", 'key' => {"neighborhood" => 1}, 'initial' => {"num coffeeshops" => 0}, '$reduce' => MongoDB::Code->new(code => $reduce) This would return something like: { 'ok' => '1', 'keys' => 4, 'count' => '487', # total number of documents 'retval' => [ { 'neighborhood' => 'Soho', 'num coffeeshops' => '23' }, { 'neighborhood' => 'Chinatown', 'num coffeeshops' => '14' }, { 'neighborhood' => 'Upper East Side', 'num coffeeshops' => '10' }, { 'neighborhood' => 'East Village', 'num coffeeshops' => '87' } ] }; Thus, there are 23 coffeeshops in Soho, 14 in Chinatown, and so on. See <http://www.mongodb.org/display/DOCS/Aggregation> for more details on grouping. MapReduce MapReduce is a powerful aggregation tool. (For traditional queries, you should use "MongoDB::Collection::query".) This example counts the number of occurences of each tag in a collection. Each document contains a "tags" array that contains zero or more strings. my $map = <<MAP; function() { this.tags.forEach(function(tag) { emit(tag, {count : 1}); }); } MAP my $reduce = <<REDUCE; function(prev, current) { result = {count : 0}; current.forEach(function(item) { result.count += item.count; }); return result; } REDUCE my $cmd = Tie::IxHash->new("mapreduce" => "foo", "map" => $map, "reduce" => $reduce); my $result = $db->run_command($cmd); See the MongoDB documentation on MapReduce for more information (<http://dochub.mongodb.org/core/mapreduce>). UPDATING
Positional Operator In MongoDB 1.3.4 and later, you can use positional operator, "$", to update elements of an array. For instance, suppose you have an array of user information and you want to update a user's name. A sample document in JavaScript: { "users" : [ { "name" : "bill", "age" : 60 }, { "name" : "fred", "age" : 29 }, ] } The update: $coll->update({"users.name" => "fred"}, {'users.$.name' => "george"}); This will update the array so that the element containing "name" => "fred" now has "name" => "george". perl v5.14.2 2011-08-29 MongoDB::Examples(3pm)
All times are GMT -4. The time now is 01:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy