Oracle equivalent to SQL Server Table Variables ?

Does Oracle have anything equivalent to SQL Server table variables, that can be used in the JOIN clause of a select statement ?
What I want to do is execute a query to retrieve a two-column result, into some form of temporary storage (a collection ?), and then re-use that common data in many other queries inside a PL/SQL block. I could use temporary tables, but I'd like to avoid having to create new tables in the database, if possible. If I was doing this in SQL Server, I could use a table variable to do this, but is there anything similar in Oracle ? SQL Server example:
use Northwind
DECLARE @myVar TABLE(CustomerID nchar(5), CompanyName nvarchar(40))
INSERT INTO @myVar(CustomerID, CompanyName)
select CustomerID, CompanyName
from Customers
--Join the variable onto a table in the database
SELECT *
FROM @myVar mv join Customers
on mv.CompanyName = Customers.CompanyName
The closest I've found in Oracle is to use CREATE TYPE to create new types in the database, and use TABLE and CAST to convert the collection to a table, as shown below. I can't see anyway without creating new types in the database.
CREATE TYPE IDMap_obj AS Object(OldID number(15), NewID number(15));
CREATE TYPE IDMap_TAB IS TABLE OF IDMap_obj;
DECLARE
v_Count Number(10) := 0;
--Initialize empty collection
SourceIDMap IDMap_TAB := IDMap_TAB();
BEGIN
--Populate our SourceIDMap variable (dummy select statement for now).
FOR cur_row IN (select ID As OldID, ID + 10000000 As NewID From SomeTable) LOOP
SourceIDMap.extend;
SourceIDMap(SourceIDMap.Last) := IDMap_obj(cur_row.OldId, cur_row.NewId);
END LOOP;
--Print out contents of collection
FOR cur_row IN 1 .. SourceIDMap.Count LOOP
DBMS_OUTPUT.put_line(SourceIDMap(cur_row).OldId || ' ' || SourceIDMap(cur_row).NewId);
END LOOP;
--OK, can we now use our collection in a JOIN statement ?
SELECT COUNT(SM.NewID)
INTO v_Count
FROM SomeTable ST JOIN
TABLE(CAST(SourceIDMap As IDMap_TAB)) SM
ON ST.ID = SM.OldID;
DBMS_OUTPUT.put_line(' ' );
DBMS_OUTPUT.put_line('v_Count is ' || v_Count);
END;

Hi, got this from our plsql guys:
The term "table function" is a bit confusing here. In Oracle-speak, it means a function that can be used in the from list of a select statement thus:
select * from Table(My_Table_Function()),..
where...
The function's return type must be a collection that SQL understands. So for the interesting case -- mimicking a function with more than one column -- this would be a nested table of ADTs where both the ADT and the nested table are defined at schema level. PL/SQL -- by virtue of some clever footwork -- allows you to declare the type as a nested table of records where both these types are declared in a package spec. This alternative is generally preferred, especially because the nested table can be of Some_Table%rowtype (or Some_Cursor%rowtype if you prefer).
As I understand it from our man on the ANSI committee, our use terminology follows the standard.
The construct below seems to be a bit different (though there are similarities) because it appears from your code sample that it's usable only within procedural code. And the object from which you select is a variable rather than a function.
So, after that preamble... the answer would be:
No, we don't have any constructs to let you "declare" something that looks like a regular schema-level table as a PL/SQL variable -- and then use (static) SQL on it just as if it were a schema-level table.
But yes, you can use PL/SQL's pipelined table function to achieve much of the same effect.
Look at the attached Table_Function.sql.
It shows that you can populate a collection of records using ordinary PL/SQL code. You can't use SQL for insert, update, or delete on such a collection. I see that SQL Server lets you do
insert into Program_Variable_Table select... from Schema_Level_Table
The PL/SQL equivalent would be
select...
bulk collect into Program_Variable_Collection
from Schema_Level_Table
The attached shows that once you have populated your collection, then you can then query it with regular SQL -- both from inside PL/SQL code and from naked SQL.
and the code is here
CONNECT System/p
-- Drop and re-create "ordinary" user Usr
EXECUTE d.u
CONNECT Usr/p
create table Schema_Things(ID number, Description Varchar2(80))
create package Pkg is
subtype Thing_t is Schema_Things%rowtype;
type Things_t is table of Thing_t; -- index by pls_integer
Things Things_t;
-- PLS-00630: pipelined functions must have
-- a supported collection return type
-- for "type Things_t is table of Thing_t index by pls_integer".
function Computed_Things return Things_t pipelined;
procedure Insert_Schema_Things(No_Of_Rows in pls_integer);
end Pkg;
create package body Pkg is
function Computed_Things return Things_t pipelined is
Idx pls_integer;
Thing Thing_t;
begin
Idx := Things.First();
while Idx is not null loop
pipe row (Things(Idx));
Idx := Things.Next(Idx);
end loop;
end Computed_Things;
procedure Insert_Schema_Things(No_Of_Rows in pls_integer) is
begin
Things := Things_t();
Things.Extend(No_Of_Rows);
for j in 1..No_Of_Rows loop
Things(j).ID := j;
Things(j).Description := To_Char(j, '00009');
end loop;
insert into Schema_Things
select * from Table(Pkg.Computed_Things());
end Insert_Schema_Things;
end Pkg;
-- Test 1.
begin Pkg.Insert_Schema_Things(100); end;
select * from Schema_Things
-- Test 2.
begin
Pkg.Things := Pkg.Things_t();
Pkg.Things.Extend(20);
for j in 1..20 loop
Pkg.Things(j).ID := j;
Pkg.Things(j).Description := To_Char(j, '00009');
end loop;
for j in 1..5 loop
Pkg.Things.Delete(5 +2*j);
end loop;
end;
select * from Table(Pkg.Computed_Things())
/

Similar Messages

  • Oracle equivalent of SQL Server's "FOR XML" and "OPENXML"

    Hi
    Can someone please tell what are the Oracle's equivalent of SQL Server's "FOR XML" and "OPENXML" features?

    Probably you can try General XML forum General XML
    Gints Plivna
    http://www.gplivna.eu

  • XML output from oracle equivalent to sql server

    Hi,
    I need an equivalent sql server 2005 equivalent output from oracle.
    Tried with DBMS_XMLGEN.getxml, xforest etc. But I am not able to get desired output.
    Could anyone help me in giving a hint to do so.
    Here below i am pasting sql server 2005 query and output, oracle query and output.
    SELECT top 5
    P.process_id AS Ppid,
    P.name AS Pn,
    P.group_id AS Pg,
    P.locked AS Pl,
    P.build AS Pb,
    100 AS qcount,
    200 AS ocount,
    PI.question_id AS PIqid,
    PI.process_id AS PIpid,
    PI.posx AS PIpx,
    PI.posy AS PIpy,
    PI.innertext AS PItext,
    PI.itemtype AS PItype,
    PI.linkfrom AS PIfrom,
    PI.linkto AS PIto,
    PI.associated AS PIas,
    PI.content_id AS PIc,
    PI.exitpoint1_id AS PIe1,
    PI.exitpoint2_id AS PIe2,
    PI.exitpoint3_id AS PIe3,
    PI.resolveidentifier AS PIri,
    PI.libquestion_idfk AS PIlqid,
    PI.followoncall AS PIfoc,
    PI.userinput AS PIui,
    PI.isLocked AS PIstls,
    PI.PreviousAnswer as PIPAns,
    PI.VisibleToAgent as PIVAgent,
    PI.RetryAttempt as PIRetry,
    PI.Tags as PITag,
    PO.option_id AS POoid,
    PO.question_id AS POqid,
    PO.process_id AS popid,
    PO.posx AS POpx,
    PO.posy AS POpy,
    PO.opt_innertext AS POtext,
    PO.opt_linkfrom AS POfrom,
    PO.opt_linkto AS POto,
    PO.libquestion_idfk AS POlqid,
    PO.liboption_idfk AS POloid
    FROM
    dbo.processes_ec AS P WITH (nolock) INNER JOIN
    dbo.vw_ProcessesQuestions_Simulator_v6 AS PI WITH (nolock)
    ON P.process_id = PI.process_id LEFT OUTER JOIN
    dbo.vw_ProcessesOptions_Simulator_v6 AS PO WITH (nolock)
    ON PI.question_id = PO.question_id AND PI.process_id = PO.process_id
    ORDER BY Ppid, PIqid, POoid ASC
    FOR XML AUTO, ELEMENTS
    O/P
    <P>
    <Ppid>450</Ppid>
    <Pn>CBB1015 - Router Firewall Settinngs Process</Pn>
    <Pg>9</Pg>
    <Pl>0</Pl>
    <Pb>5</Pb>
    <qcount>100</qcount>
    <ocount>200</ocount>
    <PI>
    <PIqid>1</PIqid>
    <PIpid>450</PIpid>
    <PIpx>366</PIpx>
    <PIpy>-516</PIpy>
    <PItext>CBB1015 - Router Firewall Settinngs Process</PItext>
    <PItype>Title</PItype>
    <PIto>2</PIto>
    <PO />
    </PI>
    <PI>
    <PIqid>2</PIqid>
    <PIpid>450</PIpid>
    <PIpx>366</PIpx>
    <PIpy>-437</PIpy>
    <PItext>Is the customers PC Firewall turned off?</PItext>
    <PItype>Question</PItype>
    <PIfrom>1</PIfrom>
    <PIto>2.2,2.1</PIto>
    <PO>
    <POoid>1</POoid>
    <POqid>2</POqid>
    <popid>450</popid>
    <POpx>-50</POpx>
    <POpy>70</POpy>
    <POtext>Yes</POtext>
    <POto>5</POto>
    </PO>
    <PO>
    <POoid>2</POoid>
    <POqid>2</POqid>
    <popid>450</popid>
    <POpx>50</POpx>
    <POpy>70</POpy>
    <POtext>No</POtext>
    <POto>3</POto>
    </PO>
    </PI>
    <PI>
    <PIqid>3</PIqid>
    <PIpid>450</PIpid>
    <PIpx>468</PIpx>
    <PIpy>-344</PIpy>
    <PItext>Advise the customer to turn off the PC Firewall in order to continue. Has this been done?</PItext>
    <PItype>Question</PItype>
    <PIfrom>2.2</PIfrom>
    <PIto>3.2,3.1</PIto>
    <PIc>278</PIc>
    <PO>
    <POoid>1</POoid>
    <POqid>3</POqid>
    <popid>450</popid>
    <POpx>-50</POpx>
    <POpy>70</POpy>
    <POtext>Yes</POtext>
    <POto>5</POto>
    </PO>
    <PO>
    <POoid>2</POoid>
    <POqid>3</POqid>
    <popid>450</popid>
    <POpx>50</POpx>
    <POpy>70</POpy>
    <POtext>No</POtext>
    <POto>4</POto>
    </PO>
    </PI>
    </P>
    Oracle query and output
    select DBMS_XMLGEN.getxml('select * from (SELECT
    P.process_id AS Ppid,
    P.name AS Pn,
    P.group_id AS Pg,
    P.locked AS Pl,
    P.build AS Pb,
    100 AS qcount,
    200 AS ocount,
    PI.question_id AS PIqid,
    PI.process_id AS PIpid,
    PI.posx AS PIpx,
    PI.posy AS PIpy,
    PI.innertext AS PItext,
    PI.itemtype AS PItype,
    PI.linkfrom AS PIfrom,
    PI.linkto AS PIto,
    PI.associated AS PIas,
    PI.content_id AS PIc,
    PI.exitpoint1_id AS PIe1,
    PI.exitpoint2_id AS PIe2,
    PI.exitpoint3_id AS PIe3,
    PI.resolveidentifier AS PIri,
    PI.libquestion_idfk AS PIlqid,
    PI.followoncall AS PIfoc,
    PI.userinput AS PIui,
    PI.isLocked AS PIstls,
    PI.PreviousAnswer as PIPAns,
    PI.VisibleToAgent as PIVAgent,
    PI.RetryAttempt as PIRetry,
    PI.Tags as PITag,
    PO.option_id AS POoid,
    PO.question_id AS POqid,
    PO.process_id AS popid,
    PO.posx AS POpx,
    PO.posy AS POpy,
    PO.opt_innertext AS POtext,
    PO.opt_linkfrom AS POfrom,
    PO.opt_linkto AS POto,
    PO.libquestion_idfk AS POlqid,
    PO.liboption_idfk AS POloid
    FROM
    processes_ec P INNER JOIN
    vw_ProcessesQuestions_Sim_v6 PI
    ON P.process_id = PI.process_id LEFT OUTER JOIN
    vw_ProcessesOptions_Sim_v6 PO
    ON PI.question_id = PO.question_id AND PI.process_id = PO.process_id
    ORDER BY Ppid, PIqid, POoid ASC) where rownum<=5') from dual
    O/P
    <?xml version="1.0"?>
    <ROWSET>
    <ROW>
    <PPID>450</PPID>
    <PN>CBB1015 - Router Firewall Settinngs Process</PN>
    <PG>9</PG>
    <PL>0</PL>
    <PB>5</PB>
    <QCOUNT>100</QCOUNT>
    <OCOUNT>200</OCOUNT>
    <PIQID>1</PIQID>
    <PIPID>450</PIPID>
    <PIPX>366</PIPX>
    <PIPY>-516</PIPY>
    <PITEXT>CBB1015 - Router Firewall Settinngs Process</PITEXT>
    <PITYPE>Title</PITYPE>
    <PITO>2</PITO>
    </ROW>
    <ROW>
    <PPID>450</PPID>
    <PN>CBB1015 - Router Firewall Settinngs Process</PN>
    <PG>9</PG>
    <PL>0</PL>
    <PB>5</PB>
    <QCOUNT>100</QCOUNT>
    <OCOUNT>200</OCOUNT>
    <PIQID>2</PIQID>
    <PIPID>450</PIPID>
    <PIPX>366</PIPX>
    <PIPY>-437</PIPY>
    <PITEXT>Is the customers PC Firewall turned off?</PITEXT>
    <PITYPE>Question</PITYPE>
    <PIFROM>1</PIFROM>
    <PITO>2.2,2.1</PITO>
    <POOID>1</POOID>
    <POQID>2</POQID>
    <POPID>450</POPID>
    <POPX>-50</POPX>
    <POPY>70</POPY>
    <POTEXT>Yes</POTEXT>
    <POTO>5</POTO>
    </ROW>
    <ROW>
    <PPID>450</PPID>
    <PN>CBB1015 - Router Firewall Settinngs Process</PN>
    <PG>9</PG>
    <PL>0</PL>
    <PB>5</PB>
    <QCOUNT>100</QCOUNT>
    <OCOUNT>200</OCOUNT>
    <PIQID>2</PIQID>
    <PIPID>450</PIPID>
    <PIPX>366</PIPX>
    <PIPY>-437</PIPY>
    <PITEXT>Is the customers PC Firewall turned off?</PITEXT>
    <PITYPE>Question</PITYPE>
    <PIFROM>1</PIFROM>
    <PITO>2.2,2.1</PITO>
    <POOID>2</POOID>
    <POQID>2</POQID>
    <POPID>450</POPID>
    <POPX>50</POPX>
    <POPY>70</POPY>
    <POTEXT>No</POTEXT>
    <POTO>3</POTO>
    </ROW>
    <ROW>
    <PPID>450</PPID>
    <PN>CBB1015 - Router Firewall Settinngs Process</PN>
    <PG>9</PG>
    <PL>0</PL>
    <PB>5</PB>
    <QCOUNT>100</QCOUNT>
    <OCOUNT>200</OCOUNT>
    <PIQID>3</PIQID>
    <PIPID>450</PIPID>
    <PIPX>468</PIPX>
    <PIPY>-344</PIPY>
    <PITEXT>Advise the customer to turn off the PC Firewall in order to continue. Has this been done?</PITEXT>
    <PITYPE>Question</PITYPE>
    <PIFROM>2.2</PIFROM>
    <PITO>3.2,3.1</PITO>
    <PIC>278</PIC>
    <POOID>1</POOID>
    <POQID>3</POQID>
    <POPID>450</POPID>
    <POPX>-50</POPX>
    <POPY>70</POPY>
    <POTEXT>Yes</POTEXT>
    <POTO>5</POTO>
    </ROW>
    <ROW>
    <PPID>450</PPID>
    <PN>CBB1015 - Router Firewall Settinngs Process</PN>
    <PG>9</PG>
    <PL>0</PL>
    <PB>5</PB>
    <QCOUNT>100</QCOUNT>
    <OCOUNT>200</OCOUNT>
    <PIQID>3</PIQID>
    <PIPID>450</PIPID>
    <PIPX>468</PIPX>
    <PIPY>-344</PIPY>
    <PITEXT>Advise the customer to turn off the PC Firewall in order to continue. Has this been done?</PITEXT>
    <PITYPE>Question</PITYPE>
    <PIFROM>2.2</PIFROM>
    <PITO>3.2,3.1</PITO>
    <PIC>278</PIC>
    <POOID>2</POOID>
    <POQID>3</POQID>
    <POPID>450</POPID>
    <POPX>50</POPX>
    <POPY>70</POPY>
    <POTEXT>No</POTEXT>
    <POTO>4</POTO>
    </ROW>
    </ROWSET>
    Any help really appreciated.
    Thanks in advance

    Here are the links ->
    http://www.psoug.org/reference/xml_functions.html
    http://www.psoug.org/reference/dbms_xmlgen.html
    http://www.adp-gmbh.ch/ora/sql/xmlelement.html
    http://www.oracle-base.com/articles/9i/SQLXML9i.php
    http://download.oracle.com/docs/cd/B10500_01/appdev.920/a96620/toc.htm
    Regards.
    Satyaki De

  • Oracle equivalent of sql server CLRSplitSting function

    Hello Friends,
    I have a query in SQL Server - which is getting data .
    select addl_info_id, sort_seq, code, row_data, addl_info_group_id, group_sort_seq, group_row_data       from dbo.CLRSplitString('2406081,2410381,2427008,2430449,2466981,2495083,1586420,2406081,2410381,2427008,2430449,2466981,2495083,1586420','',',') x         join ein_addl_info_v v on x.col1 = v.addl_info_id       order by sort_seq
    we have same data in oracle too so I converted the above sql server query to ORACLE Like this ..
    select addl_info_id, sort_seq, code, row_data, addl_info_group_id, group_sort_seq, group_row_data from ( with t as (
    select '2406081,2410381,2427008,2430449,2466981,2495083,1586420,2406081,2410381,2427008,2430449,2466981,2495083,1586420','',',' str from dual
    *)select regexp_substr(str,'[^,]+',1,level) sub_str from t connect by level <= regexp_count(str,',') + 1) x*
    join cnh_cs_targ_csce_eur_1.ein_addl_info_v v  on x.sub_str= v.addl_info_id     order by sort_seq
    but I am not getting any data . Can any one check whether the above oracle query is equivalent to SQL query stated above .
    thanks/Kumar
    Edited by: kumar73 on 15 Feb, 2013 8:47 AM

    Here your code:
    WITH t AS
       SELECT '2406081,2410381,2427008,2430449,2466981,2495083,1586420,2406081,2410381,2427008,2430449,2466981,2495083,1586420' str
        FROM DUAL
    SELECT REGEXP_SUBSTR (str, '[^,]+', 1, LEVEL) sub_str
       FROM t
    CONNECT BY LEVEL <= REGEXP_COUNT (str, '[^,]+');The reason of the problem is that in your query the column str was having value , (comma). Your query:
    select '2406081,2410381,2427008,2430449,2466981,2495083,1586420,2406081,2410381,2427008,2430449,2466981,2495083,1586420','',',' str from dual;was returning 3 columns.
    I have also modified the condition in REGEXP_COUNT.
    Regards.
    Al
    Edited by: Alberto Faenza on Feb 15, 2013 5:53 PM
    Explanation added.

  • Oracle equivalent to SQL SERVER CLRClipString function

    Hello Friends,
    I am running the following sql query in SQL SERVER successfully ..
    select * from
    CLRSplitString('33,54,105,148,149,163,165,179,193,195,201,202,234,239,279,282,297,299,329,332,350,415,417,439,440,500,552,570,589,603,628,655', '', ',') x
    join dbo.PART_ADDL_INFO_NAMES_V v on x.col1 = v.addl_info_name_id
    I want to implement the same sql statement in ORACLE .
    I created the function that takes comma seperated string and display as single column .. I want to implemement in oracle as a sql statement ..
    create or replace function str2tbl
         (p_str in varchar2,
         p_delim in varchar2 default '.')
         return myTableType
    as
         l_str     long default p_str || p_delim;
         l_n     number;
         l_data myTableType := myTabletype();
    begin
         loop
         l_n := instr( l_str, p_delim );
         exit when (nvl(l_n,0) = 0);
         l_data.extend;
         l_data( l_data.count ) := ltrim(rtrim(substr(l_str,1,l_n-1)));
         l_str := substr( l_str, l_n+length(p_delim) );
         end loop;
         return l_data;
    end;
    DECLARE
    v_array mytabletype;
    BEGIN
    v_array := str2tbl ('10.01.03.04.234');
    FOR i IN 1 .. v_array.COUNT LOOP
         DBMS_OUTPUT.PUT_LINE (v_array(i));
    END LOOP;
    END;
    10
    01
    03
    04
    234
    appreciate your help ..
    thanks

    If you need to split a single string:
    with t as (
               select '33,54,105,148,149,163,165,179,193,195,201,202,234,239,279,282,297,299,329,332,350,415,417,439,440,500,552,570,589,603,628,655' str from dual
    select  regexp_substr(str,'[^,]+',1,level) sub_str
      from  t
      connect by level <= regexp_count(str,',') + 1
    SUB_STR
    33
    54
    105
    148
    149
    163
    165
    179
    193
    195
    201
    SUB_STR
    202
    234
    239
    279
    282
    297
    299
    329
    332
    350
    415
    SUB_STR
    417
    439
    440
    500
    552
    570
    589
    603
    628
    655
    32 rows selected.
    SQL> SY.
    P.S. REGEXP_COUNT is available in 11g only. If you are on 10g use:
    with t as (
               select '33,54,105,148,149,163,165,179,193,195,201,202,234,239,279,282,297,299,329,332,350,415,417,439,440,500,552,570,589,603,628,655' str from dual
    select  regexp_substr(str,'[^,]+',1,level) sub_str
      from  t
      connect by level <= length(regexp_replace(str,'[^,]')) + 1
    /

  • Oracle equivalent to SQL Server Profiler

    Is there a tool within Oracle that can analyse SQL coming from an application similar to the Profiler tool within SQL Server.
    I have looked at my available icons within the Oracle Enterprise Manager Console but I have not noticed anything I think would do the same job.
    Thanks
    Andrew.

    ALTER SESSION SET SQL_TRACE=TRUE;
    -- invoke the SQL code
    ALTER SESSION SET SQL_TRACE=FALSE;
    now find the trace file within ./udump folder
    tkprof <trace_file.trc> trace_results.txt explain=<username>/<password>
    the contents of trace_results.txt contains the results

  • Oracle Equivalent to SQL Server Linked Servers

    I'm trying to make that jump over to Oracle. One of the things I am doing is replicating everything I do in MS SQL 2005 to Oracle 10g. In Microsoft, I pull data from AS/400 through a linked server. I'm having trouble finding anything on the web on this, but I think I'm using the wrong terms. So I have two questions.
    1. What do you called a linked server in the Oracle terminology?
    2. Is it possible to link to AS/400 through Oracle and ISeries Access?
    Thanks
    Adam

    For Oracle to Oracle links, look up 'database links'; for third party databases, look at 'Heteregenous services'.
    There are two varieties of heteregenous services - 'transparent gateways' which are paid options and the basic version which essentially uses ODBC.

  • ORA-02070: Error when updating a SQL Server table thru an Oracle View

    I have a SQL Server table TIMESHEET which contains a number of VARCHAR and NUMERIC columns plus a DATETIME column.
    Only the DATETIME column is giving me trouble.
    On the ORACLE side I have a view which selects from the SQL Server table but in order to get the SELECT to work, I had to either put a CAST or TO_DATE function call around the DATETIME field
    Below is the relevant part of the 2 view definitions I have tried
    create view TIMESHEET as
    SELECT
    "TsKeySeq" as TS_KEY_SEQ,
    "EmployeeNo" as EMPLOYEE_NO,
    CAST("PeriodEnding" AS DATE) as PERIOD_ENDING,
    . . . (more columns - not relevant)
    FROM [email protected];
    An update to the view generates this message
    ORA-02070: database OLEMSQLPSANTDAS6 does not support CAST in this context
    create view TIMESHEET as
    SELECT
    "TsKeySeq" as TS_KEY_SEQ,
    "EmployeeNo" as EMPLOYEE_NO,
    TO_DATE("PeriodEnding") as PERIOD_ENDING,
    . . . (more columns - not relevant)
    FROM [email protected];
    An update to the view generates this message
    ORA-02070: database OLEMSQLPSANTDAS6 does not support TO_DATE in this context
    If I don't include either the TO_DATE() or CAST() then I get
    Select Error: ORA-28527: Heterogeneous Services datatype mapping error
    ORA-02063:preceding line from OLEMSQLSANTDAS6
    Does anyone have any idea how to update a SQL Server DATETIME column thru an ORACLE view?

    You can't cast accross heterogenious databases and there is no need to. HSODBC treats SQL Server DATETIME column as DATE. For example, I have SQL Server table:
    CREATE TABLE [Ops].[T_JobType](
         [JobType] [varchar](50) NOT NULL,
         [JobDesc] [varchar](200) NULL,
         [InsertDt] [datetime] NOT NULL CONSTRAINT [InsertDt_00000006]  DEFAULT (getdate()),
         [InsertBy] [varchar](128) NOT NULL CONSTRAINT [InsertBy_00000006]  DEFAULT (user_name()),
         [LastUpdated] [datetime] NOT NULL CONSTRAINT [LastUpdated_00000006]  DEFAULT (getdate()),
         [LastUpdatedBy] [varchar](128) NOT NULL CONSTRAINT [LastUpdatedBy_00000006]  DEFAULT (user_name()),
    CONSTRAINT [T_JobType_PK] PRIMARY KEY CLUSTERED
         [JobType] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 100) ON [DATA01FG]
    ) ON [DATA01FG]Now on Oracle side I do:
    SQL> desc "Ops"."T_JobType"@pbods
    Name                                      Null?    Type
    JobType                                   NOT NULL VARCHAR2(50)
    JobDesc                                            VARCHAR2(200)
    InsertDt                                  NOT NULL DATE
    InsertBy                                  NOT NULL VARCHAR2(128)
    LastUpdated                               NOT NULL DATE
    LastUpdatedBy                             NOT NULL VARCHAR2(128)
    SQL> select "InsertDt" from "Ops"."T_JobType"@pbods;
    InsertDt
    18-AUG-08
    09-OCT-08
    22-OCT-09
    18-AUG-08
    19-NOV-08
    SQL> SY.

  • Writing a stored procedure to import SQL Server table data into a Oracle table

    Hello,
    As a new DBA I have been tasked with writing a stored procedure to import SQL Server table data into an Oracle table. I have been given many suggestions on how to do it from SQL Server but I I just need to write a stored procedure to run it from the Oracle side. Suggestions/guidance on where to start would be greatly appreciated! Thank you!
    I started to write it based on what I have but I know this is not correct :/
    # Here is the select statement for the data source in SQL Server...
    SELECT COMPANY
    ,CUSTOMER
    ,TRANS_TYPE
    ,INVOICE
    ,TRANS_DATE
    ,STATUS
    ,TRAN_AMT
    ,CREDIT_AMT
    ,APPLD_AMT
    ,ADJ_AMT
    ,TRANS_USER1
    ,PROCESS_LEVEL
    ,DESCRIPTION
    ,DUE_DATE
    ,OUR_DATE
    ,OUR_TIME
    ,PROCESS_FLAG
    ,ERROR_DESCRIPTION
      FROM data_source_table_name
    #It loads data into the table in Oracle....   
    Insert into oracle_destination_table_name (
    COMPANY,
    CUSTOMER,
    TRANS_TYPE,
    INVOICE,
    TRANS_DATE,
    STATUS,
    TRANS_AMT,
    CREDIT_AMT,
    APPLD_AMT,
    ADJ_AMT,
    TRANS_USER1,
    PROCESS_LEVEL,
    DESCRIPTION,
    DUE_DATE,
    OUR_DATE,
    OUR_TIME,
    PROCESS_FLAG,
    ERROR_DESCRIPTION)
    END;

    CREATE TABLE statements would have been better as MS-SQL and Oracle don't have the same data types.
    OUR_DATE, OUR_TIME will (most likely) be ONE column in Oracle.
    DATABASE LINK
    Personally, I'd just load the data over a database link:
    insert into oracle_destination_table_name ( <column list> )
    select ... <transform data here>
    from data_source_table@mssql_db_link
    As far as creating the database link from Oracle to MS-SQL ... that is for somebody else to answer.
    (most likely you'll need to use an ODBC driver)
    EXTERNAL TABLE
    If the data from MS-SQL is in a CSV file, just use and external table.
    same concept:
    insert into oracle_destination_table_name ( <column list> )
    select ... <transform data here>
    from data_source_external_table
    MK

  • What is the easiest way to export all tables data from Oracle to MS SQL Server?

    Hello MS,
    I would like to export all tables from Oracle 11.2 to MS SQL Server 2012 R1.
    Using the tool "Microsoft SQL Server Migration Assistant v6.0 for Oracle" did not work for me because there are too many warnings and errors regarding the schema creation (MS cannot know it because they are not the schema designer). My idea is
    to leave/skip the schema creation to the application designer/supplier and instead concentrate on the Oracle data export and MS SQL data import.
    What is the easiest way to export all tables data from Oracle to MS SQL Server quickly?
    Is it:
    - the „MS SQL Import and Export Data“ Tool
    - the “MS SQL Integration Services” Tool
    - not Oracle dump *.dmp format because it is a propritery binary format
    - flat file *.csv (delimited format)
    Thanks!

    Hi lingodingo,
    If you want to directly export all tables from Oracle database to SQL Server, I suggest you use SQL Server Import and Export Wizard. Because you just need to follow the wizard with GUI, this is the easiest way.
    If you want to make some modification for the tables‘ data before loading to SQL Server, I suggest you use SQL Server Integration Services package. For more details, please refer to the following similar thread:
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/38b2bed2-9d4e-48d4-a33f-1d9eed1c062d/flat-file-to-sql-server?forum=sqldatamining
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Create and insert into table from Oracle to MS SQL server.

    Hello,
    Oracle Database 11g and Red hat 5
    I have a very different kind of issue. I am handling the ORACLE db(remote db with all the important data). On the other side their is a MS SQL server db(local db with some testing data in it). All the users will access the ORACLE db for the actual processing but for sometime they need to apply some of their own concepts. So they will transfer the data from ORACLE to MS sql server.
    I want to create a code in ORACLE db like a procedure , which will create a table in MS sql server , insert data into it,Also create some metadata table to keep some of my table's info on MS SQL serve db,If the table is present it should append the data, .... like many things ...
    Overall my question is , how can i write a code to make these operation on a remote db, that to these operations are DDL and on MS SQL Server(Non-Oracle) ???
    Please guide me with some ideas or solutions ...
    Also provide if you have some good links to study ...
    thanks in advance.

    I'm not sure why you never visit http://tahiti.oracle.com prior to asking any question. Is it forbidden in your locale? Are you afraid of it? Will your salary be decreased when you visit the documentation?
    http://www.oracle.com/pls/db111/search?word=sql+server&partno=
    should provide sufficient information.
    Your doc question must be considered a violation of Forum Etiquette and an abuse of this forum.
    Sybrand Bakker
    Senior Oracle DBA

  • Replication of table from Oracle 10g to sql server 2000

    Could i replicate table from Oracle 10g to sql server online. we have tables with same configuration and if any change happen in oracle 10g or sql server in that table we need to replicate that change to other database.
    What is the solution for this two way replication between sql server and Oracle 10g

    But the tutorial is saying that i will have to install Oracle database on the server already having sql server, is it client or whole database, if it is then it will acquire lot of resource.
    I want to find out that for Heterogenous Service ODBC, we need third party software for ODBC Driver of SQL SERVER for Linux and secondly if we use Transparent Gateway then what are the steps for its configuration.
    I could not find steps of configuration of Transoparent gateway, when i am trying to install Transparent gateway from Universal installer, it is not there. where do i find it , Do i need to purchase it too.

  • How to insert into SQL server table form oracle forms

    I created a form with oracle as my database. But there one trigger where I need to insert the data into a sql server table.
    Is this possible. If so can any help me out.
    Thanks in advance.
    Asha

    Hi,
    You can insert into sql server database using the following steps
    Note: Check wether you are using Forms 32 bit drivers. If not the Odbc data source will not work.
    step 1: Create ODBC data source for SQL server(one time creation);
    step 2: Logout from Oracle and login to SQL server giving the user name,password and host string as odbc:<odbc datasource name>;
    step 3: use EXEC SQL statement to insert the values into the SQL server and then logout and login again to your oracle database.
    Second Method.
    Check the sql server documentation to insert the values using command line parameters. Then you can call the host command to execute this.
    Third Method.
    Write a VB exe to enter the values in the sql server making two connections one to oracle another to SQL server and then getting values from Oracle and putting in the SQL server database. You can call this exe using the Host command.
    Hope this will help You.
    Regards
    Gaurav Thakur

  • Developing database views between Oracle and SQL Server tables

    I am on Oracle 10.2, my organization has many SQL Server databases as well and has now made
    SQL server as company standard so many new databases will be developed in SQL Server. It is of course
    not possible to convert all Oracle databases to SQL Server, so a mix environment will exist. Two questions:
    1.     Is it possible to develop database views in Oracle (10g in my case) which join Oracle tables with tables in SQL Server 2008? If yes, how. I have seen some heterogeneous connectivity setup to connect SQL Server to Oracle, but not sure whether it is possible to develop a database view across two databases.
    2.     I know it is not a SQL Server forum, but many DBA’s know both Oracle and SQL Server. Is it possible to develop views in SQL Server (SQL Server 2008 R2 in my case) which join Oracle 10g and SQL Server 2008 tables? I know in SQL Server, there is way to set up linked servers, but do not know whether it is possible to develop views.
    Thanks a lot for your insight.

    You can create views that join local Oracle tables and remote SQL Server tables. I'm pretty sure you can do the reverse as well but I haven't personally done it.
    However, I would be very concerned about the performance you'd get if you created that sort of view. You'd very frequently end up in a situation where Oracle has to pull all the data in the remote table across the database link in order to apply predicates and join the data locally. That could be disastrous from a performance standpoint.
    Justin

  • How to provide joins between oracle tables and sql server tables

    Hi,
    I have a requirement that i need to generate a report form two different data base. i.e Oracle and Sql Server.
    how to provide joins between oracle tables and sql server tables ? Any help on this
    Regards,
    Malli

    user10675696 wrote:
    I have a requirement that i need to generate a report form two different data base. i.e Oracle and Sql Server. Bad idea most times. Heterogeneous joins do not exactly scale and performance can be severely degraded by network speed and b/w availability. And there is nothing you can do in the application and database layers to address performance issue at the network level in this case - your code's performance is simply at the mercy of network performance. With a single glaring fact - network performance is continually degrading. All the time. Always. Until it is upgraded. When the performance degradation starts all over again.
    If the tables are not small (few 1000 rows each) and row volumes static, I would not consider doing a heterogeneous join. Instead I would rather go for a materialised view on the Oracle side, use a proper table and index structure, and do a local database join.

Maybe you are looking for

  • Money Illegally Taken from my account by BT

    I'm sorry its resorted to having to create a profile on the BT Forum but I'm at the end of my tether and if this is not resolved have been informed to take legal action. I was a loyal BT Customer for 8 years but decided in November 2012 to switch to

  • Transport datasource in r/3

    hello BW Experts, I have created a generic datasource on a already existing table, there is not extra logic involved. i followed the below procedure to transport the datasource 1) se03 > change object directory entries > select object type R3TR OSOA

  • Read the content of a file attached to a document

    Hi, I have a requirement to read the content of the file attached to the document and send in the body of the email. The original get stored in the KPRO server. Can anyone suggest how can i read the content of the file stored in the KPRO server. HTTp

  • Configure Oracle BBDD to work with Windows KDC

    Hi all, I'm having problems in configure Oracle 11g running in Windows 2003 Server R2 with another W2003 Server R2 where AD is located and also KDC server. The problem is when I try to retrieve TG initial ticket using okinit. Output of okinit after e

  • Planner Profile

    Hi Experts, Please help me on this ; We have defined a new planning profile ( T-Code : KP66 ) and assigned that to a new planning profile in SPRO following the path : SPRO -> controlling -> cost center -> accounting -> planning -> manual planning ->