I'm using the RODBC
package inside an ORACLE DATA BASE (DB). Everything is doing very well, but I need to obtain a table from this DB and some variables as character type, not numbers.
So, I made my query like this:
e ManzResul_VIII<-sqlQuery(con,"select distinct t.fono_id_dis,
t.id_predio,
t.co_calle,
t.nu_casa,
t.x,
t.y,
t.plancheta from c_araya.proy_dist08_todo t where nvl(t.fono_tipo_dis, '-') not in ('CLIENTE', 'POTENCIAL', 'CARTERA') and nvl(t.x, 0) <> 0 ")
Is impossible to get the ID number as Character, this query change the type of my iDs variables from Character to Numeric type (The ID has a zero at the beginning, but has been changed it into a number). I have read the function description, but I can see how to manage it.
Any idea would be really appreciated, thanks in advance!
Query using DBI You can query your data with DBI by using the dbGetQuery() function. Simply paste your SQL code into the R function as a quoted string. This method is sometimes referred to as pass through SQL code, and is probably the simplest way to query your data. Care should be used to escape your quotes as needed.
You can run SQL code in an R Markdown document. Create a sql code chunk and specify your connection with the connection = con code chunk option. R Markdown provides options that simplify using SQL with R.
How to convert a numeric field to a character field in OpenEdge SQL? To convert a numeric field to a character value in OpenEdge SQL or Progress SQL-92, use the TO_CHAR scalar function or the CONVERT function: SELECT TO_CHAR (CustNum) FROM PUB.
R makes performing common data analysis tasks such as loading data, transforming, manipulating, aggregating, charting and sharing your analyses very easy, and the workflow is much more seamless than in SQL.
Change the query to cast the id to the data type you want:
select distinct cast(t.fono_id_dis as varchar(255)) as id
. . .
This should work with most databases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With