R programming error: RODBC

0 votes

I'm unable to understand how to pass a dataframe's column value to a query? 

I've stored the values in dframe$number:

dataframe <- sqlQuery(connection, "
+ SELECT
+ dimension1,
+ FROM
+ table1,
+ WHERE
+ dimension1 = dframe$number ")

I get the error:

 [1] "42S22 904 [Oracle][ODBC][Ora]ORA-00904: \"dframe$number\": invalid identifier\n"
Mar 6 in Data Analytics by Tyrion anex
• 8,270 points
37 views

1 answer to this question.

0 votes

You can perform quasi-perl-style string interpolation using the gsubfn package

library(gsubfn)

num <- 3
dataframe <- fn$sqlQuery(connection, 
         "SELECT dimension1 FROM table1 WHERE dimension1 = $num ")

Make use of paste or sprintf to construct the string:

sql <- paste("SELECT dimension1 FROM table1 WHERE dimension1 =", num)
sqlQuery(connection, sql)

or

sql <- sprintf("SELECT dimension1 FROM table1 WHERE dimension1 = %d", num)
sqlQuery(connection, sql)
answered Mar 6 by Sophie may
• 9,530 points

Related Questions In Data Analytics

0 votes
2 answers

Error: could not find function - R Programming

Yes, Just like @Maverik said, It happens ...READ MORE

answered Aug 22 in Data Analytics by anonymous
• 25,820 points
2,367 views
0 votes
1 answer

"no applicable method" Error in r programming

This is caused by using an object-oriented ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 40,440 points
68 views
0 votes
1 answer

“subscript out of bounds” Error in r programming

This error is likely to occur when ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 40,440 points
1,411 views
0 votes
1 answer

R Programming error: twitteR OAuthFactory object

You need to install the following packages: install.packages(c('ROA ...READ MORE

answered Jan 11 in Data Analytics by Tyrion anex
• 8,270 points
76 views
0 votes
1 answer

R programming error

Alright, you can either use gsub to match the ...READ MORE

answered Dec 18, 2018 in Data Analytics by Tyrion anex
• 8,270 points
26 views
0 votes
1 answer

R Programming: Market Basket Analysis Error

The basket.sorted() has less than 5 rules. Refer ...READ MORE

answered Feb 11 in Data Analytics by Sophie may
• 9,530 points
115 views
0 votes
1 answer

R Programming: regexpr error

The below code will help: gregexpr("D", x) # [[1]] # ...READ MORE

answered Feb 21 in Data Analytics by Tyrion anex
• 8,270 points
27 views
0 votes
1 answer

R programming: Graphs

Try this: ggplot(dfc, aes(x=x, y=y, colour=f, fill=f, ymin=y-se, ...READ MORE

answered Feb 21 in Data Analytics by Tyrion anex
• 8,270 points
24 views
0 votes
1 answer

R programming: Unexpected symbol error

Format your code this way: myfunction <- function() ...READ MORE

answered Dec 17, 2018 in Data Analytics by Sophie may
• 9,530 points
231 views
0 votes
1 answer

R Programming error in 'fert'

You're using a factor: fert <- factor(c(50,20,10,10,20,50)) levels(fert) #[1] ...READ MORE

answered Dec 27, 2018 in Data Analytics by Sophie may
• 9,530 points
43 views