Which ORM's support the upsert statement? - oracle

For example, in Hibernate, there is the saveOrUpdate method, which does a select first, and depending on if there is a record available, it does and insert or an update. However, Oracle DB supports an 'upsert', in which you can do an insert or an update in one statement.
I know Hibernate doesn't support this out of the box, are there any other ORM's that support it? Also, has anyone managed to override Hibernate to support upserts?
Many thanks

Related

Truncate Oracle table using Spark

my first question here!
I’m learning Spark and so far is awesome. Now I’m writing some DFs to Oracle using DF.write.mode(“append”).jdbc
Now, I need to truncate the table since I don’t want to append. If I use “overwrite” mode, it will drop the table and create a new one but I’ll will have to reGRANT users to Get access to it. Not good.
Can I do something like truncate in Oracle using spark SQL? Open for suggestions! Thanks for your time.
There is an option to make Spark to truncate target Oracle table instead of dropping it. You can find the syntax https://github.com/apache/spark/pull/14086
spark.range(10).write.mode("overwrite").option("truncate", true).jdbc(url, "table_with_index", prop)
Depending on the versions of Spark, Oracle and JDBC driver, there are other parameters that you could use to make the truncate on cascade as you can see from https://spark.apache.org/docs/latest/sql-data-sources-jdbc.html
From my experience, that works on some of DB engines, and depends a lot on the JDBC that you use, because not all of them support it
Hope this helps

How can i get the queries executed on a particular table in database

I wanted to find the queries that were executed on a particular table in database
Let me know the query...through which I can fetch the queries that were executed on a particular table
You can use the AUDIT feature of Oracle DB as concrete and customized solution.
Please see my answer in the following question: SQL - Find statement that insert specific values
For more details regarding auditing, Please follow the Oracle documentation: https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_4007.htm
Feel free to ask in comments, if you have any doubts.
Cheers!!

Configuring EclipseLink DDL Generation to ignore tables

I have several externally supplied tables which I can't modify. In my case these are things like the built in Oracle tables.
What I have is several entities which map on to these tables, but when I do my DDL generation I don't want them to be generated. Is there an annotation or an attribute I can set to ignore certain entities in the DDL generation?
You could simply switch to "create" ddl from "drop-create". The "create" calls for the existing tables would be ignored. Unfortunately there is currently no option in EclipseLink to prevent a table from being dropped when using "drop-create". Your best option is to have EclipseLink write the DDL to file and remove the lines for tables you do not want altered. It is likely that something similar will be available in a future version of EclipseLink. You can monitor and provide feedback on the currently active "extensions" feature in EclipseLink : http://wiki.eclipse.org/EclipseLink/Development/2.4.0 . Monitor this page for more information.

How can I tell if a Materialized View in Oracle is being used?

We have some Materialized views in our Oracle 9i database that were created a long time ago, by a guy no longer working here. Is there an easy (or any) method to determine whether Oracle is using these views to serve queries? If they aren't being used any more, we'd like to get rid of them. But we don't want to discover after the fact that those views are the things that allow some random report to run in less than a few hours. The answer I'm dreaming of would be something like
SELECT last_used_date FROM dba_magic
WHERE materialized_view_name = 'peters_mview'
Even more awesome would be something that could tell me what actual SQL queries were using the materialized view. I realize I may have to settle for less.
If there is a solution that requires 10g, we are upgrading soon, so those answers would be useful also.
Oracle auditing can tell you this once configured as per the docs. Once configured, enable it by "AUDIT SELECT ON {name of materialized view}". The audit trail will be in the AUD$ table in the SYS schema.
One method other than auditing would be to read the v$segment_statistics view after one refresh and before the next refresh to see if there have been any reads. You'd have to account for any automatic statistics collection jobs also.
V$SQLAREA table has two columns which help identify the queries executed by the database.
SQL_TEXT - VARCHAR2(1000) - First thousand characters of the SQL text for the current cursor
SQL_FULLTEXT - CLOB - All characters of the SQL text for the current cursor
We can use this columns to find the queries using the said materialized views

Can I detect the version of a table's DDL in Oracle?

In Informix, I can do a select from the systables table, and can investigate its version column to see what numeric version a given table has. This column is incremented with every DDL statement that affects the given table. This means I have the ability to see whether a table's structure has changed since the last time I connected.
Is there a similar way to do this in Oracle?
Not really. The Oracle DBA/ALL/USER_OBJECTS view has a LAST_DDL_TIME column, but it is affected by operations other than structure changes.
You can do that (and more) with a DDL trigger that keeps track of changes to tables. There's an interesting article with example here.
If you really want to do so, you'd have to use Oracle's auditing functions to audit the changes. It could be as simple as:
AUDIT ALTER TABLE WHENEVER SUCCESSFUL on [schema I care about];
That would at least capture the successfuly changes, ignoring drops and creates. Unfortunately, unwinding the stack of the table's historical strucuture by mining the audit trail is left as an exercise to the reader in Oracle, or to licensing the Change Management Pack.
You could also roll your own auditing by writing system-event triggers which are invoked on DDL statements. You'd end up having to write your own SQL parser if you really wantedto see what was changing.

Resources