Converting SQL from MSSQL to Oracle
Hi,
I have the following sql written in TSQL. I wanted to convert it into SQL so that i can use it in oracle.
select distinct DT_APPROVAL_GRP,dbo.MagicToDbBoolean(DT_MUST_BE_APPVD) as DT_MUST_BE_APPVD,DT_REVIEW_INTERVAL,DT_REVIEW_UNIT,
case DT_APPROVAL_GRP
when ' ' then '[NoGroup]'
else DT_APPROVAL_GRP
END + '['+cast(dbo.MagicToDbBoolean(DT_MUST_BE_APPVD) as varchar) + ']' +'[' cast( DT_REVIEW_INTERVAL as varchar) ']' +'[' + cast(DT_REVIEW_UNIT as varchar)+']' as ReviewModelCode from dt_document_Type, ag_approval_group WHERE (AG_NAME = DT_APPROVAL_GRP or DT_APPROVAL_GRP=' ' );
Thanks in advance.
Muneer
Hello
Case is more flexible than decode as you have more comparison operators at your disposal and you can combine multiple conditions in a single test, although for numbers and dates you can use decode with SIGN(arithmetic expression). You can nest decodes(as with case), but they can sometimes be difficult to understand if they're not formatted properly.
I have been told that decode is faster than case, but I haven't personally benchmarked it, so it could well be one of the many myths.
HTH
Similar Messages
-
How can i convert data from DBF to oracle database 10g?
Sir,
How can i convert data from DBF to oracle database 10g?I assume you at least know how to dump the contents of foxpro dbf file into CSV format.
Regarding SQL*Loader, hope this demo makes it a bit clear to you...
http://www.princeton.edu/~storacle/sqlloader_demo.shtml
I agree that it is an old web page (references Oracle 8.0.5) but basics remain the same.
If it is still unclear to you after referring above link, then get an Oracle consultant. -
Convert sql select statement to oracle
Hi All,
Can anyone help me converting this Sql select statement to oracle ....
-----------------------------------------Query--------------------------------------------------------------
select emp_master.emp_code ,
emp_master.dept_cd ,
attendance_master.daily_attn_code ,
attendance_master.linked_column ,
case when location.payroll_status <> 'N' and eDocsNetEmployeesLeave.StartDate < dateadd(mm, 1 , convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01'))
then
dateadd(mm, 1 , convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01'))
when eDocsNetEmployeesLeave.StartDate < convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01')
then convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01') else eDocsNetEmployeesLeaveDetails.StartDate
end ,
eDocsNetEmployeesLeaveDetails.NoOfDays,
case when eDocsNetEmployeesLeave.StartDate > location.next_pay_date
then convert(datetime , convert(varchar, dateadd(ss,-1, dateadd(mm, 1, convert(datetime , datename(yy,eDocsNetEmployeesLeave.StartDate)+ '/' + datename(mm,eDocsNetEmployeesLeave.StartDate)+ '/01') )),106) )
else
case when location.payroll_status <> 'N'
then dateadd(mm,1,location.next_pay_date)
else location.next_pay_date
end
end as PaymentDate ,
isnull(grade_master.leave_type,'C') ,
eDocsNetEmployeesLeave.StartDate ,
eDocsNetEmployeesLeaveDetails.LeaveType
from eDocsNetEmployeesLeave ,
eDocsNetEmployeesLeaveDetails ,
eDocsNetLeaveTypes ,
emp_master ,
grade_master ,
attendance_master ,
location
where eDocsNetEmployeesLeaveDetails.RequestID = eDocsNetEmployeesLeave.RequestID and
eDocsNetEmployeesLeave.EmployeeID = emp_master.emp_code and
eDocsNetEmployeesLeaveDetails.LeaveType = eDocsNetLeaveTypes.LeaveTypeID and
eDocsNetLeaveTypes.loc_cd = emp_master.loc_cd and
location.loc_cd = emp_master.loc_cd and
attendance_master.loc_cd = emp_master.loc_cd and
attendance_master.linked_column = eDocsNetLeaveTypes.LinkedAttendance and
grade_master.loc_cd = emp_master.loc_cd and
grade_master.grade_cd = emp_master.grade_cd and
eDocsNetEmployeesLeaveDetails.RequestID = @RequestID
order by eDocsNetEmployeesLeaveDetails.StartDate
Thanks in Advance
SmileySeems like you want to convert a SQL statement from the ??? dialect to the Oracle dialect. *(It would be useful to indicate the non-ANSI standard SQL you are starting with.)
Part of the problem is that you use several date related functions. Some are unnecessary in Oracle and some need to translated into Oracle functions as found in the Functions section (chapter 5) of the SQL Reference manual at http://www.oracle.com/pls/db102/homepage
Note that columns and expressions of type 'date' in ORacle always contain all of "yyyy mm dd hh mi ss" and you need to format and trauncate as necessary.
Also note that '09-JAN-31' is NOT an Oracle date, but rather a character representation of a date which must be converted to/from a date expression. You will often need to use the to_date() and to_char() functions with a format mask as the second parameter. This is also descreibed in the first 2 chapters of the SQL Reference manual. -
Convert Sql server Storeprocedure to Oracle Storeprocedure
Hi I vant to convert a sql server storeprocedures to oracle storeprocedure .
I need a convertor if anybody know a aplication that performed it please tell me.Hi Hoek,
I have tried this:
1. Get the DATETIME into a VARCHAR2 variable.
2a. Then, I use a TIMESTAMP variable and TO_TIMESTAMP like this:
v_tmst := TO_TIMESTAMP (r_typ.date1, 'DD.MM.YYYY HH24');2b. Or the function CAST:
v_tmst := CAST (r_typ.date1 AS TIMESTAMP);Same result, I lose the HH:MI:SS.FFF just in the moment the DATETIME from SQL Server is copied into an Oracle VARCHAR2 variable.
I also read the article you linked (I also read it before I wrote the 1st posting, but not with deep detail).
I'm afraid this cannot help me, or at least I'm not able to find out how.
They talk about ODI, but I'm not using that tool.
Moreover, they talk about creating a table, but they don't say anything regarding the conversion itself and how to get the miliseconds.
Don't know whether there is something I can take from here or not.
Anyway, thank you for the repply.
Francisco.
Edited by: FranBlanes on 30.08.2012 04:27 -
Help in to convert sql from CASE to DECODE in 11g
11gr2, Windows.
Can somebody help me out in re-writing below sql from CASE statement to DECODE ?
SELECT INVOICE_ID,sum(TOTAL_EXCL_VAT),LEVEL2 as descr,
sum(case when instr(LEVEL2,'Internet')>0 then SUM_QUANTITY else 0 end) as KB --- >> Here
from rator_cdr.INVOICE_DETAIL_LINE
WHERE INVOICE_ID ='000000000000000000' and CALLER='0000000000' and LEVEL1='Gesprekskosten'
group by LEVEL2,INVOICE_ID;ThanksThere is no difference in performance. CASE is a standard syntax that is relatively easy for any developer to read and follow. DECODE is an Oracle-specific function that is much less flexible (you can only use equality conditions, for example) and generally results in more cryptic code.
Justin -
Heterogeneous system copy from MSSQL to Oracle
Dear Experts,
I have performed ABAP+JAVA system copy R3load based from Oracle to Oracle and MSSQL to MSSQL platform.
Homogeneous system copy many times.
But this is first time i am perfoming an Export from MSSQL source system with r3load Export method .....My Target system is havign Oracle 10.2.0.2 software installed along with installation prerequisites.
But while Importing the same MSSQL Export ...I am not getting any option for heterogeneous system copy.
I am running on ECC6.0 windows platform and i also have generated Migartion KEY.
But where should i put this key.
I have gone through system copy guide many times but unable to understand Exact options to follow to Migrate to Oracle target system. Appreciate if anyone can give me detail steps i need to carry on Target system
Best Regards,
AjitRMarkus,
Thanks for the help, i have done Export with mentioned way and this time DBSIZE.xml file got created under ORA directory ....i started installation at target system....It went smooth until phase Import java Dump Done. .....But during Post load activities It gave error...
When i tried connectivity to Oracle database it works fine and
R3trans -d gives below mentioned error....Looks like table does not exist....all ENV variables are also got set at target machine.....
Error as below
Now 'SAPSR3/<pwd>@TST' is connected (con_hdl 0, nls_hdl 0).
4 ETW000 389 0.171885
4 ETW000 [dev trc ,00000] Database NLS settings: AMERICAN_AMERICA.UTF8 23682 0.195567
4 ETW000 [dev trc ,00000] Database instance TST is running on CSSLDELL-3 with ORACLE version 10.2.0.2.0 since 20080522
4 ETW000 4056 0.199623
4 ETW000 [dev trc ,00000] Connection 0 opened (DBSL handle 0) 14523 0.214146
4 ETW000 [dblink ,01299] ***LOG BZA=>table SVERS does not exist on database [dblink#3 @ 1299]
4 ETW000 8145 0.222291
4 ETW000 [dev trc ,00000] NTAB: SELECT COMPCNT FROM DDNTT FAILED 1021 0.223312
4 ETW000 [dev trc ,00000] NTAB: SELECT VERSION FROM DDNTT FAILED 520 0.223832
4 ETW000 [dbntab.c ,00000] *** ERROR => NTAB: SELECT VERSION/DBASE FROM DDNTT FAILED
4 ETW000 505 0.224337
4 ETW000 [dbntab ,01273] ***LOG BZY=>unexpected return code 103 calling NTAB [dbntab#3 @ 12737]
Please help...Points rewarded anyways..... -
Translating SQL from MYSQL to ORACLE with more than one outer join.
I will translate the following sqlquery from MYSQL to ORACLE:
SELECT ticket.ticket_no,ticket.ticket_dato,ticket.ticket_subject,ticket.customer_id,customer_name,ticket.ticket_own_read, ticket.department_id, department.department_name, priority_name, tickstat_name, tickettype_name
FROM customer, ticket left join department
on ticket.department_id = department.department_id left join priority on ticket.priority_id = priority.priority_id
left join ticketstatus on ticket.tickstat_id = ticketstatus.tickstat_id
left join tickettype on ticket.tickettype_id = tickettype.tickettype_id
where ticket.customer_id = customer.customer_id and customer.owner_id =
#session.owner_id#
I have tried in ORACLE with:
SELECT ticket.ticket_no,ticket.ticket_dato,ticket.ticket_subject,ticket.customer_id,customer_name,ticket.ticket_own_read, ticket.department_id, department.department_name, priority_name, tickstat_name, tickettype_name
FROM customer, ticket ,department, priority, ticketstatus, tickettype
where
ticket.department_id(+) = department.department_id and
ticket.priority_id(+) = priority.priority_id and
ticket.tickstat_id(+) = ticketstatus.tickstat_id and
ticket.tickettype_id(+) = tickettype.tickettype_id and
ticket.customer_id = customer.customer_id and customer.owner_id = #session.owner_id#
I get an error:
MERANT][ODBC Oracle driver][Oracle]ORA-01417: a table may be outer joined to at most one other table
How do I translate the code to ORACLE?I think that your syntax is wrong. The (+) operator should be on the right hand table column, not the left hand table column if you want all rows on the left hand table column. If this syntax is really what you want, you can create underlying views for each join condiction.
-
To Convert Data From Access To Oracle
Hi Allz,
Is there any tool to convert mdb (microsoft data base) data to oracle 9i , because in oracle 8 there is Microsft Access Tool for Oracle, through that tool we can covert mdb data to oracle.How can we convert the same data in oracle 9i.
ThanksYou could use Oracles Migration Workbench
http://www.oracle.com/technology/tech/migration/index.html -
Hi,
I've been developing queries in Access, using pivot tables. Oracle SQL*Plus does not recognize either TRANSFORM or PIVOT keywords from Jet SQL.
Can anyone help me find the necessary equivalents for SQL*Plus?
Thanks,
JoeHi Meena,
You mention that you have created the schema and tables in Oracle using DDL scripts. Did you use the Oracle SQL Developer Migration Workbench, creating a Migration Repository, to carry out this process? I see from your other postings that you are experiencing issues using the Exporter tool, which would lead me to believe that you haven't used the Migration Workbench to migrate your database. Obviously you will need to resolve your Exporter issues before you can proceed to the next phase of the migration process. I will aim to assist you with those issues on the seperate thread - ShowSplashScreen("_OracleSplashScreen",3) error The XML file generated by the Exporter tool forms the basis of your MS Access migration.
In order to migrate your data from MS Access to Oracle using the Migrate Data option in Oracle SQL Developer, you will need to have access to the Migration Repository used for the migration of the MS Access database. The information contained in the Converted Model, in the Migration Repository, is used during the data migration process. The data migration requires the following connections:
1. a source database connection i.e. a database connection to the MS Access MDB file
2. a target database connection i.e. a database connection to the migration Oracle schema
3. a Converted Model connection
For further information on the creation of a Migration Repository, and the migration process, please refer to the accompanying documentation available via the online Help within Oracle SQL Developer, and also from OTN - http://download.oracle.com/docs/cd/E10405_01/doc/nav/portal_booklist.htm.
I hope this helps.
Regards,
Hilary -
ORA-01841 Converting SQL Server DateTime to Oracle Date
I have Oracle 11gR2 x64 running on my Win7 Enterprise x64 personal system. I'm trying to convert the TSQL to create a database in SQL Server 2008 Express for my C# class to Oracle, and I've run into a "interesting" problem loading date data.
The SQL Server 2008 TSQL InvoiceDate column in the Invoices table has datatype DATETIME:
*[InvoiceDate] [datetime] NOT NULL,*
which Oracle does not support. The Oracle InvoiceDate column in the MMAB_Invoices table has datatype DATE:
InvoiceDate DATE NOT NULL,
The fun begins with the TSQL INSERT statements (for example):
INSERT [dbo].[Invoices] ([InvoiceID], [CustomerID], [InvoiceDate], [ProductTotal], [SalesTax], [Shipping], [InvoiceTotal]) VALUES (18, 20, CAST(0x00009CFD00000000 AS DateTime), 151.0000, 11.3300, 6.2500, 168.5800)
As you can see, whoever wrote the load script thought it would be totally awesome to convert hex (binary?) data to generate a date, instead of using data readable by a human being.
BTW, the date generated is 2010-01-13 00:00:00.000.
After Reading The Fabulous Manual and searching the OTN Discussion Fora, what I came up with is
INSERT INTO MMAB_Invoices (CustomerID, InvoiceDate, ProductTotal, SalesTax, Shipping, InvoiceTotal) VALUES (20, TO_DATE(UTL_RAW.CAST_TO_VARCHAR2(HEXTORAW('00009CFD00000000')), 'YYYY-MM-DD HH:MI:SS'), 151.0000, 11.3300, 6.2500, 168.5800);
which returned
Error starting at line 846 in command:
INSERT INTO MMAB_Invoices (CustomerID, InvoiceDate, ProductTotal, SalesTax, Shipping, InvoiceTotal) VALUES (20, TO_DATE(UTL_RAW.CAST_TO_VARCHAR2(HEXTORAW('00009CFD00000000')), 'YYYY-MM-DD HH:MI:SS'), 151.0000, 11.3300, 6.2500, 168.5800)
Error report:
SQL Error: ORA-01841: (full) year must be between -4713 and +9999, and not be 0
*01841. 00000 - "(full) year must be between -4713 and +9999, and not be 0"*
**Cause: Illegal year entered*
**Action: Input year in the specified range*
The PK InvoiceID is automatically generated by a BEFORE INSERT trigger that uses a sequence.
Suggestions?
Thanks.
P.S. Happy New Year!!!Your hex conversion is certainly not returning a date format:
sql> select UTL_RAW.CAST_TO_VARCHAR2(HEXTORAW('00009CFD00000000')) from dual;
UTL_RAW.CAST_TO_VARCHAR2(HEXTORAW('00009CFD00000000'))
┐²To convert the hex number to decimal, simply use to_number:
sql> select to_number('00009CFD00000000', 'xxxxxxxxxxxxxxxx') from dual;
TO_NUMBER('00009CFD00000000','XXXXXXXXXXXXXXXX')
1.7261E+14Now, before you can make any further calculations with that number, you need to know how it represents the date of 2010-01-13. Luckily, we've got Google nowadays. ;-)
Sql server representation seems to be an 8 byte field. The first 4 bytes stores the number of days since SQL Server's epoch (1st Jan 1900). The second 4 bytes stores the number of milliseconds after midnight.
sql> select to_number('00009CFD', 'xxxxxxxxxxxxxxxx') from dual;
TO_NUMBER('00009CFD','XXXXXXXXXXXXXXXX')
40189
sql> select to_date('1900-01-01','yyyy-mm-dd') + 40189 from dual;
TO_DATE('
13-JAN-10So, the conversion would be something like this:
sql> select to_date('1900-01-01','yyyy-mm-dd') + to_number(substr('00009CFD00000000',1,8), 'xxxxxxxx') + to_number(substr('00009CFD00000000',9,8), 'xxxxxxxx') / (24*60*60*1000) from dual;
TO_DATE('
13-JAN-10Note: Oracle DATE format specifies a datetime up to the second, whereas the sqlserver DATETIME format specifies a datetime up to the millisecond; if that precision is needed, use Oracle's TIMESTAMP instead.
Note: using an internal representation is risky, implementation details may change. In this case, it seems pretty unlikely that Microsoft will ever change the datetime internal representation, since that would break lots and lots of code.
Edited by: theoa on 2-jan-2012 9:14 -
Loading ntext data from MSSQL into Oracle - field locations vary
Good afternoon/evening everyone
I'm looking for a practical solution to a data migration issue I am running into. Here's the detail.
1. Source database is Microsoft SQL Server 2008 R2
2. Destination database is Oracle 11g R2.
3. Migration strategy: Use MSSQL Management Studio Export Wizard to export all tables into flat files and then use SQL*Loader to load into Oracle.
Sounds easy...Here's the problem I'm running into:
1. Several tables have ntext data.
2. The location of ntext attribute within the table varies by table.
3. The number of ntext attributes in the source table varies by table.
4. I'm using a field delimiter to split the data.
What I am running into:
1. There is nothing within the data for the ntext field that is common that would allow me to use a CONTINUEIF to cause the multiple physical records to be concatenated into a logical record.
2. The number of physical records very for creating the logical record.
3. Other data exists after each ntext attribute that is either ntext or non-ntext data.
What I'm looking for:
1. Would like to use SQL*Loader, if possible; otherwise I'll write a PL/SQL procedure to read the data, row for row, and load it into the appropriate fields.
2. Looking for ideas from the Forum experts to provide some Control File syntax that would accomplish what I'm trying to do. I'm out of ideas.
I would appreciate some assistance and some ideas if you have any.
Thanks in advance
Stephen Karniotis
[email protected]is this what you are looking for?
select replace('this a text with\X0D\X0Ain it', '\X0D\X0A', chr(13) || chr(10)) from dualyou can do the replace directly when loading by putting "replace(:fieldname, '\X0D\X0A', chr(13) || chr(10))"
next to the field in the controll file you use with sql*loader (including the " signs). Or you can use it in an update statement.
greetings
Freek D -
Convert SQL SERVER DATETIME into ORACLE TIMESTAMP
I have to convert a column's datatype.
The source column's datatype is DATETIME which is in SQL Server to TIMESTAMP(datatype in target which is oracle)
Can anyone help me pleaseJust issue ALTER TABLE MODIFY:
SQL> create table tbl(c date)
2 /
Table created.
SQL> insert into tbl values(sysdate)
2 /
1 row created.
SQL> select to_char(c,'mm/dd/yyyy hh24:mi:ss') from tbl
2 /
TO_CHAR(C,'MM/DD/YY
12/26/2009 20:50:58
SQL> alter table tbl modify c timestamp
2 /
Table altered.
SQL> select c from tbl
2 /
C
26-DEC-09 08.50.58.000000 PM
SQL> SY. -
Converting SQL Server 2000 to Oracle 9i
Hi,
I am working on the migration of stored procs from a SQL Server 2000 database to Oracle 9i. The sqlsrvr db contains 75 relatively complex procs using temporary tables to create intermediate resultsets for further processing.
The Oracle 9i environment has very strictly standards and temporary tables are not allowed.
Is it standard practice to use PL/SQL tables to simulate the functionality of temp tables?
I understand you can now use SQL against PL/SQL tables under certain circumstances.
I would envisage using the PL/SQL tables in multi-table joins with schema tables.
Any ideas whether I am going down the wrong path.
Thanks in advance,
Garrett DonnellyGarrett,
Note that there is also an parser option to 'Generate8i temp tables', where the data in the permanent tables is seperated from other sessions by the use of an extra Session id colum.
Please post the results of your PL/SQL table experiences.
Regards,
Turloch
Oracle Migration Workbench Team -
Migrating from mssql to oracle or postgres to oracle
I have a database driven web application written in J2EE. Currently this application works with Microsoft SQL 7.0 and Postgres 7.3. It uses various datatypes and also has many stored procedures. I will be migrating actual data, table definations and stored procedures.
Can you please tell me whether to go for MS SQL to oracle migration or postgresql to oracle?Hi Margaret,
The Oracle Migration Workbench MS SQL Server 7 plugin will migrate your MS SQL Server 7 schema, stored programs and data to Oracle. You can freely download the Migration Workbench from the Migration Technology Center on OTN at http://otn.oracle.com/tech/migration/content.html.
Currently the Migration Workbench does not support migrations to postgres.
I hope this helps,
Tom. -
Convert Sql server database into oracle
hi friends
i have a very smal database of sql server containing 8 tables
i want to convert my databse into oracle plz tell me in detail coz i dont know any thing about it.
plz help me
take care
byeIf the amount of data is small, you might look into Microsoft Data Transformation Services (DTS), which comes with SQL Server. This provides an easy to use GUI for mapping data between two sources.
A few warnings:
- If you let DTS create your Oracle tables, beware that that table / column names may be created as case-sensitive and data types may not be what you expect
- If you are transferring a lot of data (e.g. millions of rows), performance will be terrible.
Maybe you are looking for
-
Using multiple iPhones questions
Hello all, I have had my iPhone 4 for over a year and am very happy with it. My father is thinking of getting one also, however I need some clarification on a number of issues. 1. Is it possible for two iPhones to be backed up to iCloud without shari
-
Getting files from laptop to iPad for email
I have been stuck trying to find a solution for this problem. I have a desktop, laptop and iPad2. My iPad generally syncs with the desktop (which has my photos, complete iTunes library, etc.). I regularly travel to a location that has no internet acc
-
Datagrid itemRenderer custom component formatting
OK, so this is my first attempt at an itenRenderer. This works below, but I have to imagine there is an easier way. There is also a problem with below, where the changed field (datafield=side) after the itemRenderer is applied, the text is all out of
-
Shared computer and apps and in-app purchases.
My son and I share a computer to sync his ipod and my iphone. He downloaded a free app, which was uploaded to our computer itunes account, then downloaded onto my iphone. I ended up loving the app and want to make in-app purchases, but can't. I ge
-
Hi All, I am working on interfacing between Rosettanet and XI and i need to do the mapings. I need to import these PIPS into XI to start mapping and would like to know where i can download them from. Below are the PIPS and version i need to download.