Oracle (XE) & SQL-Developer: how to find out the time/date/timestamp format being used? - oracle

I recently wrote a tool that extracts certain data from our DBs. It runs as PL/SQL script running in SQLDeveloper (either in a worksheet or as extension plugin) and produces its output to the SQLDeveloper log-window.
This worked all fine on my system, but now I encountered an issue when users are on systems with a different language or more specific with different default time/date/timestamp formats than on the machine on which I had been developing and testing this.
Now - I am not sure: is the format of dates, times and timestamps controlled by the DB or by SLQ-Developer? In my understanding these PL/SQL scripts are sent to the DB for execution and their output is sent back to SQL-Developer. That would mean for me, that the format of the output depends solely on the DB (or the system on which the DB executes). Or are the NLS setting of the client (SQL-Developer) somehow involved here?
To make my tool auto-adjust to these settings I will need to be able to query these formats - either from the DB in use (Oracle 12.2 or Oracle XE 18/19 in our case) or from SQLDeveloper.
Assuming, it's the DB: Is there a table that contains the default format strings that are being used for select results?
Note: The point is NOT how to format dates etc. as strings, but the other way round:
I get the the query results as strings in the log-window. These contain dates and timestamps. I now need a hint from the DB-system to figure out how to interpret these. E.g. when I get a date such as '10-11-12', is this meant to be Nov. 10th, 2012 or is meant to be Nov. 12th, 2010?
Hope I could make myself clear...

Related

GUI to oracle Change data capture

I'm learning how to implement change data capture in oracle. However, not being a DB specialist but rather a DEV, i find the process tedious with respect to other things that i have to do. I end up doing it because my DBA/DEVOP don't want to take care of it.
Hence i was wondering if there is any tool that can help set oracle change data capture. In other words a simple graphical user interface that would write the all code for me. Creation of change table, PL/SQL Script and etc....
Many thanks
topic duplicated in: dba.stackexchange
What problem are you trying to solve?
How (when) will the CDC data be consumed
Are you planning to use something akin to: Oracle 11.1 CDC doc
Be sure to heed: Oracle 11.2 CDC Warning
"Oracle Change Data Capture will be de-supported in a future release of Oracle Database and will be replaced with Oracle GoldenGate. Therefore, Oracle strongly recommends that you use Oracle GoldenGate for new applications."
The company I work for, Attunity, has a pretty slick GUI CDC tool called "Replicate".
It can directly apply changes to a selected target DB, or store changes to be applies.
Many sources (Oracle, SQLserver, DB2...) many targets (Oracle. SQLserver, Netezza, Vertica,...)
Define your source and target DB, Search/Select source table, and one click to go.
Optional transformations such as: table and column names, drop and add columns, calculate values.
Regards,
Hein.

Charset mismatch when querying from db link

I'm querying from a 10g database using a dblink to an 8i database.
select col1, col2 ... from table#my_dblink_to_8i
8i charset is IW8ISO8859P8
10g charset is WE8MSWIN1252
the data is coming out as gibrish. I've tried all of variations I can think of
to_char(col1)
cast(col1 as nchar(4))
cast(col1 as nvarchar2(4))
cast(col1 as char(4))
cast(col1 as varchar2(4))
convert(col1, 'WE8MSWIN1252', 'IW8ISO8859P8')
convert(convert(col1,'UTF8','IW8ISO8859P8'),'WE8MSWIN1252','UTF8')
all returning with either gibrish or
ORA-12704: character set mismatch
ORA-02063: preceding line from OTHERDB
any suggestions ?
Is there an intermediate charset I can convert to ?
Yes, this is a known problem that sometimes occurs. I remember the first time experiencing it using a database link between two identical Oracle 7 version and then seeing it back in 9 when using Oracle 8.1.5.
It can not always be solved. Oracle development does not seem to test as intensively with non-US characters as with US characters.
The first thing you can try is to check the EXACT versions of Oracle 8i in use. Check that the server version is 8.1.7 or newer (such as 8.1.7.4). With 8.1.5 there are known problems, I think to recall that that is the first version to do AL32UTF8.
Also check the version of the SQL*Net client installation (if you are using a separate installation, I don't think so). It must be 8.1.7 or newer also.
Also check that the characters are available in BOTH character sets. They are largely identical, but not completely. I think the 8859P8 is an international without Europ-support, whereas MSWIN1252 is something of Microsoft.
Check the NLS_LANG on all nodes in between and that the database character set is correctly configured. Make sure they are correct. The interim nodes you can change to AL32UTF8. SQL*net does no character conversion but also no checks when the client and server talk the same characterset, so bugs in the characterset setup can slumber for years.
After testing those, you might want to try convert to AL32UTF instead of UTF8 (I think it was already available by 8, don't know sure, but maybe only mainstream supported on 9i).
As a last resort, do the character conversion yourself. Use a procedure to transport it binary to the caller and do the conversion on the receiving 10g database.
Or use an ETL tool like Kettle, spooling to text files as interim or alike.
I hope this answers your question. If not, please help me with some samples of the gibberish (transporting us7ascii texts, more advanced texts, and the results of out varchar2 parameters called across dblink). If yes, please let me know too. You have a intriguing question!

JDBC query to Oracle

We are planning to migrate our DB to Oracle.We need to manually check each of the embedded SQL is working in Oracle as few may follow different SQL rules.Now my need is very simple.
I need to browse through a file which may contain queries like this.
String sql = "select * from test where name="+test+"and age="+age;
There are nearly 1000 files and each file has different kind of queries like this where I have to pluck the query alone which I have done through an unix script.But I need to convert these Java based queries to Oracle compatible queries.
ie.
select * from test where name="name" and age="age"
Basically I need to check the syntax of the queries by this.I have seen something like this in TOAD but I have more than 1000 files and can't manually change each one.Is there a way?
I will explain more i the question is not clear
For performance and security reasons you should use PreparedStatement.bind(...) rather than string concatenation to build your SQL strings.
I don't know of a way to tackle this problem other than fixing the code that needs to be fixed. If you can find common patterns then you can automate some of the editing using find/replace or sed or some other tool, as long as you diff the result before checking it in.
If there are thousands of files I guess that there is a reasonable sized team that built the code this way. It seems fair to share the workload out amongst the people that built the system, rather than dump it all on one person. Otherwise you will end up as the "SQL fixing guy" and nobody else on the team will have any incentive to write SQL code in a more portable way.
Does your current application execute SQL through a common class? Could you add some logging to print out the raw SQL in this common class? From that output you could write a small script to run each statement against Oracle.

converting database formats (mysql, ms access, ms excel, IBM DB2)

We need to a good tool that we can run from a script to
automatically convert a (mysql, ms access or DB2) database
to a (mysql, ms access, ms excel or DB2) database,
while preserving the data types as much as possible (text, int, decimal, time...).
Do you know of such a tool?
I am looking for a solution, such as IBM Data Movement Tool. this tool converts from any database to IBM DB2, automatically. it maps the data types, creates the tables, and import the data automatically. and you can run it from the command line. the only problem is that the target database can only be a db2 database. I am looking for the same type of tool, from any database to any database. http://www.ibm.com/developerworks/data/library/techarticle/dm-0906datamovement/
Best I can provide for you is SwissSQL products. I have used their trial stuff to help me convert schemas from MS SQL to Postgres, and they were quite useful.
In theory they can also convert full schemas, data, and even stored procedures. In practice you should read what their tools cover, because if you expect 100% conversion without any human intervention you will probably be disappointed.
Similar products may exist, (have you already googled for "convert DB2 to mySQL"?) but they will probably not cover exactly the mix you are interested in (for example, there may be tools specializing in converting from a range of DBs to mySQL, or from a range to MSAccess, but having a general purpose tool doing what you want for all the combination is probably too much to ask).
And I am pretty sure that in every case, you will have to verify the results and be ready to manually correct anything missing, truncated, or misinterpreted.
I don't think there's the single silver-bullet for this problem. The best thing to look for is specific tools to help you along. Some things can already be done without additional tools, e.g. exporting Excel to CSV and importing CSV with MySQL's tools. Likely you'll just need to find the best tool for each specific case (with perhaps a few combined) and selectively use each depending on your desired input/output formats.

load data into text file from oracle database views

I want to load data into text file that is generated after executing "views" in Oracle?How can I achieve this in oracle using UNIX.for example-
I want the same in Oracle on unix box.Please help me out as it alredy cosume lots of time.
your early response is highly appreciated!!
As Thomas asked, we need to know what you are doing with the "flat file". For example, if you're loading it into spreadsheet or doing some other processing that expects a defined format, then you need to use SQL*Plus and spool to a file. If you're looking to save a table (data + table definition) for moving it to another Oracle database then EXP/IMP is the tool to use.
We generally describe the data retrieval process as "selecting" from a table/view, not "executing" a table/view.
If you have access to directories on the database server, and authority to create "Directory" objects in Oracle, then you have lots of options.
For example, you can use the UTL_FILE package (part of the PL/SQL built-ins) to read or write files at the operating system level.
Or use the "external table" functionality to define objects that look like single tables to Oracle but are actually flat files at the OS level. Well documented in the Oracle docs.
Also, for one-time tasks, most of the tools for working SQL and PL/SQL provide facilities for moving data to and from the database. In the Windows environment, Toad's good at that. So is Oracle's free SQLDeveloper, which runs on many platforms. You wouldn't want to use those for a process that runs every day, but they're fine for single moves. I've generally found these easier to use than SQLPlus spooling, but that's a primitive version of the same functionality.
As stated by others, we need to know a bit more about what you're trying to do.

Resources