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, 2019 in Data Analytics by Tyrion anex
• 8,560 points
126 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, 2019 by Sophie may
• 10,100 points

Related Questions In Data Analytics

+3 votes
2 answers

Error: could not find function - R Programming

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

answered Aug 22, 2019 in Data Analytics by anonymous
• 32,490 points
20,794 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
• 51,970 points
602 views
+1 vote
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
• 51,970 points
6,876 views
0 votes
1 answer

R Programming error: twitteR OAuthFactory object

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

answered Jan 11, 2019 in Data Analytics by Tyrion anex
• 8,560 points
219 views
+1 vote
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,560 points
87 views
+1 vote
1 answer

R Programming: Market Basket Analysis Error

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

answered Feb 11, 2019 in Data Analytics by Sophie may
• 10,100 points
496 views
+1 vote
1 answer

R Programming: regexpr error

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

answered Feb 21, 2019 in Data Analytics by Tyrion anex
• 8,560 points
79 views
+1 vote
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, 2019 in Data Analytics by Tyrion anex
• 8,560 points
94 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
• 10,100 points
1,431 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
• 10,100 points
112 views