How Does SEQUENCE Object Work in Sql Loader - sql

I can not find proper documentation of SQEUENCE object used in SQL Loader. Can someone please refer to me to a proper use of SEQUENCE object. How does it get its value. where does it persist etc.
How SEQUENCE (MAX, 1) in SQL LOADER is different from My_Seq.nextval in oracle client ?

Direct load does not allow the My_Seq.nextval entity, however, as you've indicated, the SEQUENCE(max,1) construct can be used. The documentation is found in the utilities reference:
https://docs.oracle.com/database/121/SUTIL/toc.htm

Related

Determine/Find underlying SQL field type of a Django Field

Is there an easy way to determine or find the underlying SQL field type of a Django Field, for any of the supported by default database backends? I have searched on the web and there is no documentation over how the Django fields are represented in SQL in each of the supported databases. The only way for me to see the underlying SQL field type, is to run the mysqlmigrate command of manage.py and examine the SQL code.
The type depends on the database backend, so you need to get a db connection first:
from django.db import connection
and now you can look up the field via the model Meta API:
my_field = MyModel._meta.get_field('my_field_name')
and use its db_type method:
my_field.db_type(connection)
which will return something like "varchar(10)".
Be sure you really need to do this, though. Usually this information is only useful inside migrations.

Can Entity Framework 5 map an Oracle function returning a nested table?

I have an Oracle function that returns a nested table of an Oracle user defined type.
If I call the function from TOAD or SQL developer with a syntax like this:
SELECT * FROM TABLE(MYFUNCTION('SOME_STRING_PARAM'))
I get the expected result.
I am even able to create .NET classes from Visual Studio Server Explorer wizard for the user defined types.
However when I try to create import function from the Entity Framework model wizard I don't get a proper option to define the returned type.
Am I trying to do something not supported?
Import function doesn't behave the way you might expect with ODP.NET. It assumes that the first SYS_REFCURSOR it finds as an OUT parameter is the "return value" of the Entity Function.
Therefore, you will need to wrap your function with a stored procedure that places the nested table data in a REF CURSOR.
Then you need to learn about the required metadata in the config file for this REF CURSOR. In the online help for Oracle Developer Tools for Visual Studio, read the Entity Framework section for more information.
Here is a walkthrough that shows how to set up an Import Function:
https://apex.oracle.com/pls/apex/f?p=44785:24:106387346683725:::24:P24_CONTENT_ID,P24_PROD_SECTION_GRP_ID,P24_PREV_PAGE:10068,,24
Due to the complexity of all this, I don't advise using Imported Functions with non scalar Oracle Stored Functions or Procedures return values unless you absolutely have to.

Hibernate native sql query

Perfectly fine ms-sql statement
SELECT distinct ProductLineCode ,
(SELECT CAST(ItemName + ', ' AS VARCHAR(MAX)) FROM Product spt
where spt.ProductLineCode = pt.ProductLineCode FOR XML PATH (''))
as ItemNames FROM Product pt where ProductLineCode is not null
cause error when executed as native query in hibernate.
org.hibernate.MappingException: No Dialect mapping for JDBC type: -16
I guess that JDBC type: -16 is boolean but that says me nothing. Product table has xml mapping and works well for months.
Could you please guide me what to try next?
You might as advised in comments be able to get something similar to work by changing the types in the sql.
But if that doesn't bring success, you might also be able to tell hibernate how to deal with this type by changing the Dialect class used by your application, possibly even extending the one currently used and adding a registration for the missing type.
It appears that your missing type mapping is for the type java.sql.Types.LONGNVARCHAR (by code grep, the value is -16), so a Dialect extension with a call something like
registerColumnType( Types.LONGNVARCHAR, "text" );
in the constructor may convince hibernate to treat this field as text.
If you do this you'll have to change the configuration to use your dialect by modifying the line
<property name="dialect">org.hibernate.dialect.SQLServer2012Dialect</property>
to use your own dialect class. (Note: the class in there is just a guess at what you might have there now.)
It's also possible that you just have hibernate using the wrong dialect for your DB, in which case just changing the configuration to the appropriate one would be better.
It's rarely necessary to use a custom Dialect, but this may be one of those times.

How to fetch data dynamically from an oracle table whose structure is known only at runtime using pl sql procedure?

I have been given a requirement to create a pl/sql procedure which will accept select statement as an input parameter. All data must be fetched from the query and printed in DBMS_OUTPUT.
I've researched native dynamic SQL and DBMS_SQL but was unable to figure out how to fetch and process data from a table whose structure is unknown.
Since the table name will be provided during run time, i just want to know how to store the data fetched from the query because i cant define variables or collections since the structure of table is unknown
First off, the requirement seems incredibly dubious. You should never depend on data that is written to the DBMS_OUTPUT buffer-- it is entirely up to the client to enable a buffer, to ensure that the buffer is large enough, and to display the data from the buffer to the user. By default, none of that will happen. And writing a procedure to manipulate a table whose structure is completely unknown would be incredibly unusual.
If you are really determined, however, you would likely want to take Tom Kyte's SQL Unloader which uses DBMS_SQL to write data from an arbitrary query to a flat file and modify it to write it to DBMS_OUTPUT instead.
There is an open-source utility package for generating Excel readable files within PL/SQL.
https://code.google.com/p/plsql-utils/
However, I would recommend you look into using a more general purpose language for your tool if at all possible. PL/SQL can be incredibly useful for database logic, but for interacting with the outside world, I expect you will achieve a more maintainable solution using something like Python or Java.
Although, as always YMMV :-)

Hibernate: UPDATE with a user-provided SQL code

I've been reading the documentation, but I couldn't find any information about it.
Is it possible to have Hibernate send user-provided SQL queries in order to UPDATE or to INSERT an object in the database?
In other words, is it possible to have session.saveOrUpdate( myObject ); , which generates update mySchema.myObject set field1=?, field2=?, field3=? where unique_key=?
to be replaced with a manual query from a user-provided String?
This is well described in the reference documentation. There are caveats, though : the session and the second-level cache aren't aware of the changes made to the entities, the version field is not updated, etc.
And if HQL is still not sufficient, you may always fall back to SQL queries.