conversion of code from sql server to oracle

Hi all, need help... I have the following sql server code and I need to convert this code in oracle... Please help me with this...

See you soon...



USE [HPSEB]
GO
/ * Object: UserDefinedFunction [dbo]. [ALG_GetData] Script Date: 2011-10-31 18:32:41 * /.
SET ANSI_NULLS
GO
SET QUOTED_IDENTIFIER ON
GO
-Select * from ALG_GetData (31)
ALTER FUNCTION [dbo]. [ALG_GetData] (int @code)
-RETURNS @Results TABLE (value nvarchar (4000))
RETURNS the array @temptb (sno int identity (1,1), meterno varchar (12), METERDATETIME varchar (35),)
eventoccuretime varchar (35), code int, int event_id, duration type varchar (35), int flag)
AS
-This function takes a parameter;  It's code int
BEGIN
declare @tempdate datetime
declare @TIME varchar (35)
declare @STATUS int
declare @Duration varchar (20)
declare @METERNUMBER varchar (12)
declare @METERDATE varchar (35)
declare @event_id varchar (35)
declare @sno int
declare @tempmetno varchar (12)
declare @flag int


DECLARE MyCursor cursor static for
Select event_id, TIME, STATUS, duration, METERNUMBER, METERDATE, flag
of Xml_EVENT where CODE = @code and EVENT_Id < =.
(select MAX (EVENT_Id) of xml_event where code = @code and STATUS = 0)
order by METERNUMBER, CONVERT (date, METERDATE, 103), EVENT_Id desc

OPEN mycursor
EXTRACT NEXT FROM mycursor INTO @event_id, @Duration, @TIME, @STATUS
@METERNUMBER, @METERDATE, @flag
While (@FETCH_STATUS = 0)
BEGIN
If (@STATUS = '0')

Start
insert into @temptb (event_id, meterno, METERDATETIME, eventoccuretime, code, flag)
values (@event_id, @METERNUMBER, @METERDATE, @TIME, @code, @flag)
Set @tempdate = convert (datetime,@TIME, 103)
Set @tempmetno = @METERNUMBER
end

on the other

Start
If (@TIME <>")

Start
set @Duration = DATEDIFF (MI, convert (datetime,@tempdate, 103), convert (datetime,@TIME,103))
end

on the other

Start
set @Duration = convert (varchar, (convert (int, substring (@Duration, 5.2)) * 60) +)
(convert (int, substring (@Duration, 8, 2)))
end

Select @sno = max (sno) of @temptb
Update @temptb set Duration = @Duration where sno = @sno and meterno = @tempmetno

end
SET @event_id = "
SET @TIME = "
SET @STATUS = "
SET @Duration = "
SET @METERNUMBER = "
SET @METERDATE = "
FETCH NEXT FROM mycursor INTO @event_id, @TIME, @STATUS, @Duration, @METERNUMBER, @METERDATE, @flag
END
CLOSE MyCursor
DEALLOCATE MyCursor

-update @temptb set eventrestoretime = DATEADD (MINUTE, convert (int, time), CONVERT (datetime, eventoccuretime, 105))
RETURN
END

try these below

but you must make a few changes like sno you can use a sequence and each time 'select your_seq.nextval in double sno.

create or replace package pkg_ALG_GetData as

type rw is record
(number (1) number of sno, meterno varchar2 (12), METERDATEv_TIME varchar2 (35),)
eventoccureTIME varchar2 (35), code event_id number, number, duration varchar2 (35), flag of number);

type rec_set is ref cursor return rw;
end;
/

Create procedure ALG_GetData (code number)
-Results of PERFORMANCE TABLE (value nvarchar2 (4000))
p_ret in the pkg_ALG_GetData.rec_set) as

-This function takes a parameter; This is the code number
cursor c_MyCursor is select event_id, v_TIME, STATUS, duration, METERNUMBER, METERDATE, flag
Xml_EVENT where CODE = code and EVENT_Id<>
(select MAX (EVENT_Id) of xml_event where code = code and STATUS = 0)
order of METERNUMBER, to_date (METERDATE, ' dd/mm/yyyy'), EVENT_Id desc;

r_MyCursor c_MyCursor % rowtype;

tempdate date;
v_TIME varchar2 (35)
STATE number
Duration varchar2 (20)
METERNUMBER varchar2 (12)
METERDATE varchar2 (35)
event_id varchar2 (35)
number of Sno
tempmetno varchar2 (12)
Indicator number
BEGIN

Open c_MyCursor;
loop
Search in r_MyCursor;
When the output c_MyCursor % notfound;
If (STATUS = '0') then

Start
Insert the number of temptb (event_id, meterno, METERDATEv_TIME, eventoccureTIME, code, flag)
values (r_MyCursor.event_id, r_MyCursor.METERNUMBER, r_MyCursor.METERDATE, r_MyCursor.code, r_MyCursor.flag)
tempDate = to_date (v_TIME, ' dd/mm/yyyy');
tempmetno = METERNUMBER;
end;

on the other

Start
If (v_TIME <> ")

Duration = to_date(tempdate,'dd/mm/yyyy')-to_date(v_TIME,'dd/mm/yyyy');
end;

on the other

Duration = to_char (to_number (substr (duration, 5.2)) * 60 +)
TO_NUMBER (substr (duration, 8, 2)))

Select max (sno)
in sno temptb;

Update temptb set duration = duration where sno = sno and meterno = tempmetno;

end
event_id = ";
v_TIME = ";
STATUS = ";
Duration = ";
METERNUMBER = ";
METERDATE = ";
END
CLOSE C_MyCursor;

-update temptb set eventrestorev_TIME = DATEADD (MINUTE, convert (number, duration), CONVERT (datev_TIME, eventoccureTIME, 105))

Open the p_ret for
Select event_id, meterno, METERDATEv_TIME, eventoccureTIME, code, flag
of temptb
where...;
END;
/

Tags: Database

Similar Questions

  • Migration from SQL Server to Oracle during 11.1.2.4 upgrade

    Hi all

    To further expand on the title, wanted to check if it is possible to migrate from SQL Server to Oracle, while improving 11.1.2.1 to 11.1.2.4 on brand-new material. There is a change in all the components (s/w, h/w, RDBMS) so I wanted to run this generic statement by the forum to see what the experts think.

    Where in the equation can count us on LCM?

    I know that John Goodwin had already answered a few questions on the same subject for previous versions, but as 11.1.2.4 is a different game... I would be grateful if someone could share their thoughts.

    Thank you!

    If you are installed on hardware costs and migration then it should be independent of the RDBMS. Not to say there is no problems with passing of 11.1.2.1 to 11.1.2.4 (if you use planning, for example, business rules-> Calc Manager) but they certainly should not be linked to the fact you've changed the underlying database.

  • Migration from SQL Server to Oracle database

    I have 2 questions:

    1. we intend to convert our sql server databases oracle OLTP databases. I tried to use SQL Developer to migrate a database of small sql server to oracle (size 5 GB) database. It was fine. When I tried to migrate to a different database (size 90G), it takes too much time. The problem with sql developer is I can not pick and choose tables. 250 paintings, I need to migrate tables abt 80 (the size will be abt 50 G). What is everyone can share their experiences, as appropriate, converting databases of size average sql server for oracle databases? other options?

    2. I intend to convert the sql server ddl to oracle ddl. I have tested bcp out and use sql loader to import the data. Right now I am manually creating the oracle tables sql server tables. I use http://download.oracle.com/docs/cd/E11882_01/gateways.112/e12069/apa.htm#BABCIIDI to convert the code. Are there other ways better to convert sql DDL DDL Oracle Server?

    Thanks in advance

    DDLS must be converted manually. Oracle is not SQL-Server.

    If for example, you have the option of partitioning, you should consider using the partitioning index and when it is possible. Not all tables must be hash tables. Do postpone you creation of segment or not? What type of tablespace? Set yourself free percentages and allows you to manage when the data block is on the free list and how much is reserved in the block of data to update rows in this block?

    There are many considerations to be taken with regard to the physical database design.

    Using BCP and SQL * Loader sound good. SQL * Loader is fast and scalable - use it to load up to 3.6 million lines every 60 seconds. Direct and parallel charges will give the best performance in this regard (assuming that the underlying table structure and use supports this approach).

  • Problem with the migration of key primary and foreign from SQL Server to Oracle

    Hi people, I use SQL Developer to migrate Oracle to a SQL database, and I'm stuck with a few questions:

    So far, the worst of them is the fact that I can not migrate the PKs and FKs. After having successfully captured the model DB in SQL Server and Oracle conversion, when the tool generates scripts, all ALTER TABLE queries that add pharmacokinetics and the FKs have their columns duplicate targets.

    for example: when I'm trying to migrate a simple table that contains an Id (PK) and the columns name, the tool generates the following scripts:


    PROMPT create Table TestTable...
    CREATE TABLE TestTable)
    ID NUMBER (10,0) NOT NULL,
    Name VARCHAR2 NOT NULL
    );

    The PROMPT create constraint primary key on the table TestTable PK_TestTable...
    ALTER TABLE TestTable
    ADD CONSTRAINT PK_TestTable PRIMARY KEY
    (
    ID,
    ID
    )
    ENABLE


    Regarding the FKs, the tool duplicates the columns thus:

    ALTER TABLE SomeTable
    ADD CONSTRAINT FK_SomeTable_SomeTable2 FOREIGN KEY
    (
    SomeTable2Id,
    SomeTable2Id
    )
    REFERENCES SomeTable2
    (
    ID,
    ID
    )
    ENABLE
    ;

    Does anyone have an idea on how to solve these problems? I would be very grateful for answers!

    Hi Fernando,

    I was unable to reproduce this problem. My primary / foreign keys when defined using unique columns.

    The PROMPT create constraint primary key on the suppliers table PK_Suppliers...
    ALTER TABLE suppliers
    ADD CONSTRAINT PK_Suppliers PRIMARY KEY
    (
    Vendor No.
    )
    ENABLE
    ;

    I tried a few things like
    capturing twice and rename the two models of the same
    Rename the converted templates
    but without success.
    I think that this problem occurs is in the capture phase or convert.

    (1) you perform the capture online or offline?
    (2) can provide you a DDL together for one of these tables and the indexes to see if I can reproduce?
    (3) made of capture or convert fail or be again at any stage?

    I all else fails I would attempt a capture and convert again using a new repository (create a new schema in Oracle and associate him the migration repository).

    Kind regards
    Dermot
    SQL development team

    Published by: Dermot ONeill on October 22, 2009 12:18

  • How to migrate from SQL server to oracle 11g

    Hello
    I have a lot of tables in sql server, and I want to connect them in oracle

    Welcome to the forum,

    Hello
    To create a link Oracle with SQL Server follow these steps:
    1. install Oracle ODBC drivers on the server (your Oracle database local) who will have access to the remote SQL Server database by using the database link.

    2. configuration of the ODBC connection on the local Oracle using the Windows ODBC Data Source Administrator database

    3 test pilots to verify ODBC connectivity is made to the SQL Server database.

    4. make sure that your global_names parameter is set to False.

    5. configure Oracle heterogeneous services by creating an initodbc.ora file in the Oracle database.

    7 change the Listener.ora file.

    SID_NAME is the DSN for the remote database.
    ORACLE_HOME is the real path to the file at Oracle.
    PROGRAM says Oracle heterogeneous services.

    SID_LIST_LISTENER =
    (SID_LIST =
    (SID_DESC =
    (SID_NAME = Cas30C) - enter the DSN on this line
    (ORACLE_HOME = c:\oracle10gdb)--Inscrivez your Oracle home
    (Program = hsodbc)) )

    8. change the Tnsnames.ora file. It's accessed by users Oracle database installation connect for ODBC drivers

    (DESCRIPTION =
    (ADDRESS_LIST =
    (Address = (PROTOCOL = TCP)
    (HOST =
    -(X server)
    (PORT = 1521))) -Enter the port on which the server x installing Oracle
    -is listening
    (CONNECT_DATA = (SID = Cas30c)) - enter the name of the DSN
    (HS = OK)-enter this value. He indicates to Oracle to use transfer services
    )

    9 recharge the listener on a local Oracle database

    10. create a link of database on the local Oracle installation that accesses the heterogeneous connection, which, in turn, connect to SQL Server.

    11 execute SQL Select Server from the Oracle installation using the database link

    Thank you
    BelMan :)

  • Mapping of Data Type from SQL Server to Oracle

    I use Oracle 12 c with heterogeneous services connects to SQL server DB. Some of the columns in the SB of SQL Server are defined as 'nvarchar (max). These come to Oracle as columns of type "long". I would like that these are 'varchar2' types in Oracle, so I do not have any restrictions related to the fields of type "long" when using. I can create a view in SQL Server to convert the data type IE. nvarchar (100). What is the highest value that I can use to make the data to display in Oracle as a varchar? BTW, I tried nvarchar (4000), but which showed any longer. I tried nvarchar (1000) and who showed as a varchar.

    The maximum value for an nvarchar2 in Oracle is 2000. Mapping - If the remote column is mapped to an Oracle varchar/nvarchar - depends on the type of data returned by the ODBC driver. When the driver returns SQL_Varchar, then the maximum precision is 4000 and when it will map it to SQL_WVarchar then it's 2000.

    As your Oracle database uses AL32UTF8 as set of characters that the maps to the Oracle long as your SQL Server nvarchar content is stored using characters UCS2 nvarchar (max), you will get the value that is covered by the database Oracle UTF8 character set. So it shouldn't really matter if the returned string is mapped to an Oracle, varchar or nvarchar.

  • Migration from SQL Server to Oracle

    Dear friends,

    I used several different tools as SQL Developer but couldn't really even migrate due to various errors.

    In addition to these tools, there is another way to migrate. I use Oracle 10 g and SQL Server 2005.

    Please advice.

    Thanks in advance.

    With respect,

    Nith

    I tried to follow the procedure in MS SQL Server 2005 to Oracle 11 g Migration using this guide:
    http://www.Oracle.com/technology/OBE/hol08/sqldev_migration/MSSQLServer/migrate_microsoft_sqlserver_otn.htm

    I found that a lot of tables was empty in the target database. Anyone can guide me please the ideal way to migrate data intact of the MSS to Oracle? How about full Convert 5.5 Enterprise and SwisSQL 6.0?

    Concerning
    Jimmy

  • Planning for SQL server and Oracle db

    Hi friends

    We intend to improve our environment Hyperion of 9.3.3 to 11.1.2.2. and we will go from SQL server as our RDBMS Oracle.

    If we change DBMS, do we have to rebuild the total application or is there an easy way to migrate from sql server to Oracle

    Please suggest

    Thank you

    Upgrade the application to 11.1.2.2 while remaining on the SQL Server, then use LCM to export the application, remove the application, update the data source to point to Oracle, use LCM to import.

    See you soon

    John

    http://John-Goodwin.blogspot.com/

  • Replication sql server to oracle

    Hi all

    Anyone here good at replication?

    Can you help me what freeware, or the poor woman script or cheaper tool (compared to GG) to replicate the table from sql server to oracle?

    I tried Googling it, but it is simply too complex to understand :(


    Help, please...

    Thank you

    zxy

    yxes2013 wrote:
    Well he has trigger that records the primary key and the action made next to sqlserver.

    example of

    '100', 'I '.
    '200', 'U '.
    ' 300', 'd'

    Therefore the corresponding action will be also in oracle.

    But I want a good solution of script, that's why I just give you the trick :(

    Thank you...

    You should be this announcement on the forum SQL Server, because the script will need to be written in T - SQL to execute against this DB.

  • data replication with ODI between SQL SERVER and ORACLE

    Hello world
    First of all, I want to migrate database SQL SERVER and ORACLE DB tables.
    And then make online (synchronous) replication from SQL SERVER to ORACLE using ODI.

    I have not used before ODI.
    How to use the ODI for this?

    1. create a master repository and connect to the "topology Manager.
    2. in the topology Manager, you must configure the following
    2.1 create a data server for the Oracle under Oracle database in the physical connection
    2.2. create a database for the SQL Server database server in SQL Server in the physical connection. To do this, the jdbc for sql server driver.
    2.3 implement the logical connection and frame
    2.4 create a workrepository in the topology manager repositories tab
    3. connect to the designer and follow these steps
    3.1 create a template for the SQL Server source and reverse (import) the datastores (tables) to the model.
    3.2 the value of the model for the target of the Oracle
    3.3 create a (mapping) interface, under the table in schema define the source and then add it to the target and bind
    3.3 on the flow tab, you must set the Modules (KMs) of knowledge to perform the load. You must have imported the KMs before creating the interface.
    3.4 in IKM put 'create table traget' to 'yes '.
    4 run the interface to load data from SQL to Oracle Server

    Thank you
    Fati

  • Migration from SQL Server 2005 to Oracle 10g

    Dear friends,

    I need to move my tables with data from SQL Server 2005 to Oracle 10 g. How can we make the best possible?

    Please guide me.

    Nith

    Here are the 4 options (it is perhaps more)

    * 1.* export to text file in SQL2005 and load text files using external table in Oracle

    * 2 in the Oracle ODBC for SQL Server connection configuration and simply pull the data using create table abc to select * mytable@sqlserver - if the oracle is on windows, this should be quick, free and painless, it works under unix as well. Examples

    http://www.databasejournal.com/features/Oracle/article.php/3442661/making-a-connection-from-Oracle-to-SQL-Server.htm
    http://www.easysoft.com/applications/Oracle/database-gateway-dg4odbc.html

    * 3.*, I think that you can configure the connection between SQL SERVER and Oracle

    http://support.Microsoft.com/kb/280106

    or and I hate this solution in general, but it works in the content is low

    * 4 in MS Access link to ORACLE and MS SQL Tables (two linked tables) and then create the insert query to move the data from the server sql for oracle - this solution works, but it is quite slow.

  • Need to transfer data from sql server at EBS

    I need to transfer data from Mirco Soft SQL server database Oracle (EBS).

    Please guide me how can I achieve this milestone in best way.

    Please provide the price of licenses of the Golden Gate and other product adapted SQL SERVER GATEWAY ect


    Thanks in advance

    There are a lot of options

    1 using SQL Server linked server is so easy
    http://www.mssqltips.com/sqlservertip/1433/how-to-setup-linked-servers-for-SQL-Server-and-Oracle-64-bit-client/
    2. use SSIS
    http://www.mssqltips.com/sqlservertip/2011/export-SQL-Server-data-to-Oracle-using-SSIS/
    3. using sqldeveloper
    http://St-curriculum.Oracle.com/OBE/DB/hol08/sqldev_migration/MSSQLServer/migrate_microsoft_sqlserver_otn.htm#T9

    hope this helps,

    concerning
    http://www.oracleracexpert.com
    ORA-19755 at the start of the recovery/DB
    | http://www.oracleracexpert.com/2009/09/ora-19755-could-not-open-change.html
    Error ORA-07445 and the reasons for which it
    http://www.oracleracexpert.com/2009/08/ora-07445-error.html

  • Different output for the same query in SQL Server and Oracle

    I have two tables table1 and table2

    -table1 has two columns c1 int and varchar c2. There are no constraints added in it. It contains data as shown below

    C1 c2
    -------------------
    d 6
    5 d
    102 g
    6%
    f 103
    5.
    501 j
    1 g
    601 n
    2 m

    -table2 has only a single column c1 int. There is no added in constraints. It contains data as shown below

    C1
    ----
    6
    1
    4
    3
    2

    now when I run below, given the query in sql server and oracle it gives me different results

    Select *.
    FROM table1
    table2 on table2.c1 = table1.c1 inner join (SELECT ROW_NUMBER() (any ORDER by ASC c1) AS c1 from table2)

    output of SQL server
    ------------------------
    C1 c2 c1
    --------------------------------
    1 g 1
    2 m 2
    3 h 3
    4 g 4
    5 d 5


    release of Oracle
    ----------------------
    C1 C2 C1
    ---------------------------------
    5 d 5
    4 g 4
    3 h 3
    1 g 1
    2 m 2


    If you notice the first column in the two outputs. It is sorted in sql server and no oracle.

    Why he behaves differently in oracle? Is there a way I can fix this problem in oracle?

    Thank you
    Jigs

    It is NOT a behavior "differently" in Oracle; you did not specify just an order that you expect of your results, so you'll get output in what order the fantasies of the database showing (ie. no guaranteed order). It is an artifact of the way the database chooses to collect the data and databases (or same sets of data within the same database) can and will most likely behave differently.

    Same SQL Server will not be guaranteed to always get your data in an orderly manner if you exclude the order by clause, even if you think that there always display the data in an orderly manner.

    Your solution is to add an order by clause, in the TWO databases, to force the order of the data output.

  • Error of date when migrating to SQL Server to Oracle

    Hi all

    I'm the database migration SQL Server to Oracle.

    But the tool I use is not secret the date type GBA, so I'm stuck with tables that have particular date types.

    For example: the 'DATECAPTURED' column in the 'SIGNATURE' table in the SQL Server database has values:

    15-02-2013 10:03:48.387
    15-02-2013 10:01:05.930
    15-02-2013 09:59:07.197
    15-02-2013 09:50:15.797
    15-02-2013 09:39:15.557
    15-02-2013 09:37:12.643

    Why oracle can be able to accept this type of date format? :( I thought he is more intelligent than SQLserver :)

    My solution is to change any date to varchar2 (30).

    More bright ideas? while I cannot change data types?

    Thank you
    zxy

    yxes2013 wrote:
    Thank you Justin :)

    It's just that I have a lot to learn in a fastrack way, I am a very busy person :(

    Well, just a piece of advice. If you read the watch (and wait) documentation for the responses on the web and on various forums and try to do all the work, you are probably going to stay busy!

    in any case, I'll try another tool like sqldeveloper migration. For now, I have many things to research so I'd settle for the same time, workaround. New test is required for the tool.

    Good luck!

    I was taking just opportunities here if someone met the same problem as mine ;)

    It was not a problem of IMO, but was ignorance. People here know any Timestamp data type for SOME time I think and how, because they read the docs!

    Aman...

  • Interlink with Sql server and Oracle

    Hello

    We have some data in SQL Server.
    We need to link SQL Server and Oracle Database. To make reports in Oracle Apex.

    Please someone guide me to interconnect with Oracle database

    Kind regards
    Thérèse

    Therese,
    You can find more information on gateways in this available in My Oracle Support note-

    Note to master for the Oracle Gateway (Doc ID 1083703.1) products

    Kind regards
    Mike

Maybe you are looking for