[R] RODBC looping sql script

Jason Gasper Jason.Gasper at noaa.gov
Fri Feb 26 02:41:02 CET 2010

Dear R users,

I am querying an Oracle database using sqlQuery()  from the RODBC 
package. What I would like to do is embed my R Sql query in a for loop.  
For example
suppose the data.frame "vessel" contains two columns: vessel[,1]= vessel 
id and vessel[,2]=permit year

I am using  "vessel" as an input in a SQL based function that require 
inputs of permit year and vessel id as described below:

query<-"Select * From vessel Where common.utility(vessel ID,vessel year)"


Now suppose I want to loop through my vessel table such that the vessel 
ID and vessel year  corresponds with  i:

for (i in 1:length(vessel[,1])) {
query<-"Select * From vessel Where common.utility(vessel[i,1],vessel 

Ignoring the fact I didn't include code to create and ever expanding 
final table for loop,  does anyone know how to index inside the Where 
clause of a sql statement (i.e., common.utility(vessel[i,1],vessel 


Jason Gasper
National Marine Fisheries Service
Alaska Region, Sustainable Fisheries Division
709 W. 9th St. Juneau, Alaska 99801 
Juneau, Alaska 99801

Phone  907-586-7237
Fax 907-586-7249

More information about the R-help mailing list