Вопрос

I have a MySQL table that I am acessing from R using the package "RODBC". A few of the columns has long concatenated strings separated by the STX character (\x02). I have shown a screen print of the the character below (the character is circled):

STX Symbol

I would like to run the following query from R (RODBC package) to replace the STX delimiter with a different character:

SELECT REPLACE(columnName, '**\x02**', '#') FROM tableName

I have given the complete code below:

library(RODBC)
myconn <-odbcConnect("mydsn")
query <- "SELECT REPLACE(columnName, '\x02', '#') FROM tableName"
queryResults <- sqlQuery(myconn, query)

Is there a way to accomplish this from R?

Это было полезно?

Решение

RODBC includes the function sqlQuery(), which lets you send SQL queries to the connection. According to the documentation, "The term ‘query’ includes any valid SQL statement including table creation, alteration, updates etc as well as SELECTs. The sqlQuery command is a convenience wrapper that first calls odbcQuery and then sqlGetResults. If finer-grained control is needed, for example over the number of rows fetched, additional arguments can be passed to sqlQuery or the underlying functions called directly."

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top