Bind Variable Oracle DB - R - r

I'm working on some R-scripts which require the use of database queries. My IT department mentioned to me that these scripts require too much of the database (shared pool) and I should use bind-variables.
I am not very familiar with database designing, but I found out that bind variables are like variables i.e. if you use for example and date=:var in a statement.
Is it possible to use such statements when working with R (RODBC)?
Thank u very much

It seems that using bind variables is a part of the SQL query you write. So I presume that when you connect to the Oracle database using RODBC, you can pass an valid SQL query that contains bind variable syntax, and that this would simply work.

Related

Best way for "database specific" sql scripts with Flyway

I started to use Flyway in my current project for database migrations and I like it very much. I currently use Oracle in PROD- and Derby in TEST-Environment.
Pretty soon, I did run in the problem of database specific sql commands, e.g.
ALTER TABLE T1 MODIFY F1 VARCHAR(256); on Oracle vs
ALTER TABLE T1 ALTER F1 SET DATA TYPE VARCHAR(256); on Derby.
I can't see a way to write a "vendor neutral alter table modify column datatype" sql.
What's the best way to deal with this problem using Flyway?
You can use the flyway.locations property.
In test in would look like this:
flyway.locations=sql/common,sql/derby
and in prod:
flyway.locations=sql/common,sql/oracle
You could then have the common statements (V1__Create_table.sql) in common and different copies of the DB-specific statements (V2__Alter_table.sql) in the db-specific locations.
An even better solution, in my opinion, is to have the same DB in prod and test. Yes, you do lose a bit of performance, but on the other hand you also eliminate another difference (and potential source of errors) between the environments.
The differences in SQL between Oracle and some of these desktop databases is minor. Is it possible for a developer to insert custom code to do some light-weight dynamic stripping of the SQL at runtime based on the environment (e.g. remove tablespace designation)?
I prefer this approach to relying on each developer to manually keep two sets of SQL in sync.

How to search in pl/sql local collections?

How can i make query to PL/SQL local collections like TABLE OF and VARRAY?
I searched the web , but whatever I found is to iterate over them eg. FOR LOOP!
Is there any facility to make query to them?
Thanks.
The SQL engine can make queries, the PL/SQL engine cannot. So you need to cast your collections to table types that are known to the SQL engine.
SQL doesn't know about types declared in packages, so you have to declare them at the global level.
Judging by your comment it seems like you pretty much figured it out already.

Convert PL/SQL to Hive QL

I want a tool through which I can get the respective hive query by giving the PL/SQL query. There are lots of tools available which convert sql to hql. ie: taod for cloude database. But it does not show me the respective hive query.
Is there any such kind of tool whose convert given sql to hql. Please help me.
Thanks and Regards,
Ratan
Please take a look at open-source project PL/HQL at http://www.hplsql.org/ which is now a part of Hive 2.x or higher version. It allows you to run existing SQL Server, Oracle, Teradata, MySQL etc. stored procedures in Hive.
Ratan, I did not how to start responding. So, lets start like this. I think you checked toad and thinking like there is a tool to convert SQL to hive QL. I do not think there is such a tool.
Let me clarify like this, HIVE QL, is same as SQL. Check this links before you are trying to write some queries:
https://cwiki.apache.org/confluence/display/Hive/LanguageManual,
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF.
This is simple to understand if you know sql and simple to write (as you check the HIve ql).
Hive doesnot have many operators the sql supports. For example:
select * from sales where country like 'EU~%'; "HIVE SUPPORTS LIKE"
But try this negative queries as we write in SQL :
select * from sales where country not like 'EU~%'; "HIVE DOES NOT SUPPORT"
This is just one example, I remember. There are more like this. But to deal with these hive has many like "where not" etc.
If your question is does the Hive have any PL/SQL support. Straight answer is no. But, we can check the UDF in hive and also, the PIG on Hadoop.

Why altering of a column is not permitted through query but easily done is server explorer

I am having a question i.e when i tried to alter a data type of a table by query or by modifying the data type directly i used to get some errors stating this can not be done. But where as if i open the same table in server explorer from visual studio and modify the data type it was easily done with out any errors.
I tried to modify the primary key which is a foreign key for some tables from data type int to varchar using Management Studio it throw me some errors.
But the same thing when i done through Server explorer from Visual Studio it was done in a fraction.
Can any one tell what was the difference
I think I had this issue (at least with sql server 2008):
Take a look at Tools->Options->Designers.
uncheck "Prevent saving changes that require table re-creation"
and try again.
You can see more info here about when it occurs if the option is checked.
Without seeing your specific error, all I can say is that the UI does far more than a simple command. It sometimes creates temporary storage and the copies data as it needs to, to make the experience pleasant. You should use the scripting function in the UI to capture the change and see what it's doing?
It can be done using a query, because that's exactly what SQL Server does. However, the script is considerably more complex than a simple ALTER TABLE statement; generally involving creating a temporary table with the changed datatype, copying the data from the original table, dropping the original table, then renaming the temporary table.
When modifying the structure of a table in the Design view in SSMS there is an option to generate the script for the change(s), so you can run it on multiple servers, etc. This will show you the exact process that is actually happening behind the scenes.

Accessing CoreData tables from fmdb

I'm using CoreData in my application for DML statements and everything is fine with it.
However I don't want use NSFetchedResultsController for simple queries like getting count of rows, etc.
I've decided to use fmdb, but don't know actual table names to write sql. Entity and table names don't match.
I've even looked inside .sqllite file with TextEdit but no hope :)
FMResultSet *rs = [db getSchema] doesn't return any rows
Maybe there's a better solution to my problem?
Thanks in advance
Core Data prefixes all its SQL names with Z_. Use the SQL command line tools to check out the your persistent store file to see what names it uses.
However, this is a very complicated and fragile solution. The Core Data schema is undocumented and changes without warning because Core Data does not support direct SQL access. You are likely to make error access the store file directly and your solution may break at random when the API is next updated.
The Core Data API provides the functionality you are seeking. IJust use a fetch request that fetches on a specific value using an NSExpressionDescription to perform a function. This allows you to get information like counts, minimums, maximums etc. You can create and use such fetches independent of a NSFetchedResultsController.
The Core Data API is very feature rich. If you find yourself looking outside the API for a data solution, chances are you've missed something in the API.

Resources