In SQL server we do have MASKED WITH (FUNCTION = 'default()') for dynamic data masking and the real content can be seen by only table owner.
Is there any other feature like this in Oracle.
I want to see the content only when logged in with table owner/sys, for rest it should be masked data for few columns.
Thanks in advance
Related
I made a connection to an ODBC database
con <- dbConnect(odbc(), "DTAM QA")
I listed out all the tables to confirm
dbListTables(con)
But how do I get Column Headers from my tables within 'con' / my connection object?
Let's say I wanted to get all Column Headers from a table [MobileDevicesTable] within 'con', what would the syntax look like?
I'm thinking it'd look like this, using a function like 'colnames' below, but I am not sure. Any help is appreciated :)
tableForMobileDevices <- colnames(con.MobileDevicesTable)
Because ODBC is a wrapper around SQL, so the easiest way to get things is to expressly ask for them in a query of some sort.
But if all you want is the column headings of the table, there are built in methods within ODBC that take care of these common needs. So, you could use this:
tableForMobileDevices<-dbListFields(con, "MobileDevicesTable")
You pass it your connection and the name of the table and get back the field names
I'm trying to use RJDBC to connect to a SAP HANA database and query for a temporary table, which is stored with a #-prefix:
test <- dbGetQuery(jdbcConnection,
"SELECT * FROM #CONTROL_TBL")
# Error in [...]: invalid table name: Could not find table/view #CONTROL_TBL in schema USER
If I execute the SQL statement in HANA, it works perfectly fine. I'm also able to query for permanent tables. Therefore I assume that R doesn't pass over the hashtag. Inserting escapes like "SELECT * FROM \\#CONTROL_TBL" however didn't solve my problem.
It's not possible to query for the data of a local or global temporary table from a different session, since they are by definition session-specific. In the case of a global temporary table one can query for the metadata of the table because they are shared across sessions.
Source: Tutorial for HANA temporary tables
You have to double-quote the table because it contains special characters, see SAP Help, identifiers for details.
test <- dbGetQuery(jdbcConnection,
'SELECT * FROM "#CONTROL_TBL"')
See also related discussion on stackoverflow.
Ok, local temporary tables are always only visible to the session in which they've been defined, while global temporary tables are visible just like normal tables, but the data is session private.
So, if you created the local temp. table (name starts with #) in a different session, then no wonder it cannot be found.
For your example, the question is: why do you need a temporary table in the first place?
Instead of that, you could e.g. define a view or a table function to select data from.
I have a R-code data frame that I am trying to write to an existing table in SQL Server. The data frame contains only 8 of about 12 columns contained in the table and the columns in the data frame are not in the same order as the columns in the table. SQL Server is complaining because there are columns missing and other columns that are of the wrong data type (e.g. Varchar (string)vs date, etc.).
I am looking at functions in RODBC and DBI libraries to write the data frame to my SQL Server table, but it is clear that I have to line up the data frame columns in the order expected by the table and to put null place holders in for the missing columns.
What are my options?
Thank you ahead of time for any help you can provide.
So the obvious choice from the RODBC package would be sqlSave(connection,'R data frame','SQL Table'), however as you know that doesn't work. In these cases I write an INSERT INTO statement using sqlQuery().
sqlQuery(connection, "INSERT INTO sqltable (B,C) VALUES ('i1',j1),('i2',j2)...")
Example: We have a SQL table named sqltable with columns A, B, and C. We have an R dataframe with columns B & C named Rdf. With B being of class character and C being of class numeric.
First need to put single quotes around any character fields because we will be using INSERT INTO and SQL likes single quotes around any text
Rdf$B <- paste("'",Rdf$B,"'",sep="")
Next we need to format our data so it will look like the VALUES section of an insert statement
formatRdf <- do.call(paste,c(Rdf,sep=","))
valuesRdf <- paste("(",paste(formatRdf,collapse="),("),")",sep="")
Final step of preparing the INSERT statement
sql_statement <- paste("INSERT INTO sqltable (B,C) VALUES ",valuesRdf,sep="")
Now use sqlQuery
sqlQuery(connection,sql_statement)
If you are looking for performance then probably rsqlserver will be best choice:
Sql Server driver database interface (DBI) driver for R. This is a DBI-compliant Sql Server driver based on the The .NET Framework Data Provider for SQL Server (SqlClient) System.Data.SqlClient.
Motivation
The .NET Framework Data Provider for SQL Server (SqlClient) uses its own protocol to communicate with SQL Server. It is lightweight and performs well because it is optimized to access a SQL Server directly without adding an OLE DB or Open Database Connectivity (ODBC) layer.
In the wiki of the project you will find benchmarks for RODBC, RJDBC and rsqlserver.
Once you have package to talk to database you follow standard DBI examples, so dbWriteTable or dbSendQuery for create/insert/update.
I am trying to connect to a table that is not in the sys schema. The code below works if sys.tablea exists.
conn <- dbConnect(dbDriver("MonetDB"), "monetdb://localhost/demo")
frame <- monet.frame(conn,"tablea")
If I define tablea in a different schema, e.g. xyz.tablea, then I get the error message
Server says 'SELECT: no such table 'tablea'' [#NA]
The account used to connect has rights to the table.
In a related question, is it possible to use camel-case from MonetDB.R? When I change the table name to TableA, the server again responds with
Server says 'SELECT: no such table 'tablea'' [#NA]
where the table name is all lower-case.
Using tables in other schemata is not possible with the current constructor of monet.frame. However, you can work around the issue as follows:
frame <- monet.frame(conn,"select * from xyz.tablea")
This trick also works with CamelCased table names.
For the next version, I am planning to fix the issue.
I have an Access database with a couple of tables and I want to work in just one of them. I am using library RODBC. Let's say the table that I want to work it called dtsample. And my Access database is called database.accdb
Here is my code:
library(RODBC)
dataconnect <- odbcConnectAccess2007("database.accdb")
data <- sqlQuery(dataconnect,"SELECT*dtsample columb1, columb2...)
but it does not work. How can I define the table in Access that I want to work with?
Your solution is not really one, because you just got around learning about SELECT
data <- sqlQuery(dataconnect, "SELECT * from dtsample where Columb1 = 'a' or Columb1 ='b')
My suggestion you are not fluent in SQL: Use the query designer in Access, and when it works, get the SQL code generated (View:SQL) and paste it into R.