Oracle equivalent of a variable in MS SQL Server

Hi,
I need the equivalent sql statement in oracle... Sounds real simple, but I cant seem to the the Oracle syntax
(MS SQL syntax)
declare @id integer
set @id = (select min(tranid) from tbltransaction)
select * from tbltransaction where tranid = @id
Above is a real simple example of what I want to do... I need to get a date, then use that date in a second query
The real query needs to get a date first, then execute a query based on that date. When I tried using a subquery that gets the date; it causes the job to run over an hour....
Currently I manually get the date (under 10 seconds) then enter the date into the query and run it (about 20 minutes)

here is how you do in Oracle PL/SQL :
declare
my_date date;
my_col my_tbl.col1%type;
begin
select date_col into my_date
from date_tbl where <where clause>;
select col1 into my_col
from my_tbl where date_col = my_date;
exception
<handle exceptions>
end;
There is one thing to note in PL/SQL, if your select query returns more than one row then either you've to use a collection variable or use a cursor.

Similar Messages

  • Oracle 9i on LINUX Transparent Gateway for SQL Server

    Does anybody know if there is a Transparent Gateway available for Oracle 9i on LINUX to connect to SQL Server? I have run the installer and cannot seem to find the install options for any Transparent Gateways. I am familiar with their location in the universal installer as I have installed the Oracle/SQL Server Transparent Gateway with Oracle in WinNT. Perhaps Transparent Gateways for Oracle/LINUX are not available?
    Thanks in advance.

    I have the same issue - we want to upgrade our 9.2 to 10g Linux, and need to maintain connectivity to some legacy sqlserver databases. I can't find any mention of tg4msql for linux. What gives? Anyone know the answer to this? thanks, michael

  • Study: Oracle database software has more flaws than SQL Server

    Hi,
    Study: Oracle database software has more flaws than SQL Server
    Microsoft is often unfairly slammed for security issues, says NGSS
    http://www.computerworld.com/action/article.do?command=viewArticleBasic&articleId=9005383&intsrc=hm_list
    Post your comments on this stupid artical.
    Thanks!
    M T

    This is a case where size does matter.
    When they say errors reported on oracle are about 4 times more than the ones reported on SQL server they forgot to say something like: SQL server is able to do... what a 10%, a 5% or whatever of what oracle can do.
    Anyway who sayd this forgot to say that they worked with microsoft trying to improve SQL sever security features as well.
    http://www.nextgenss.com/press-releases/ngs-and-the-sql-server-security-essential-guide/
    They have a reason to say it. Who would say "I made a bad job!"
    In my opinion there is no way yet to compare oracle to any other DBMS under any point of view.
    Bye Alessandro

  • Oracle 11.1.0.7 x64 to SQL Server 2008 connectivity

    Hi There,
    I'm trying to establish connectivity between oracle database running 11.1.0.7 64bit on windows 2008 server x64 to sql server 2008 database. Both databases (oracle and SQL) are on the same machine.
    I know with the older oracle versions, we used to setup hs connection between the two databases, however, I've been reading note 466225.1 (How To : How to Setup DG4ODBC (Oracle Database Gateway for ODBC) on Windows 32bit) on metalink and it states the following:
    >
    Please be aware:
    - DG4ODBC is first ported to 64bit Windows platforms starting with 11.2. Using a 32bit DG4ODBC on a 64bit Windows operating system is NOT certified.
    - HSOLEDB is no longer available for 11g on Windows.
    >
    So, according to the above, I'm guessing that we won't be able to use dg4odbc to establish the connectivity between the two.. how about the old hsodbc setup under ORACLE_HOME\hs\admin ? would that work? or is there another way that w can do this?
    I've been working on this and trying to get it going but not sure if I'm doing something wrong or it just doesn't work here..
    On the server I did the following:
    1. created the sqlserver DSN and tested the connection and it's all ok.
    2. added the following to the tnsnames.ora
    SQLCentralODBC  =
      (DESCRIPTION=
        (ADDRESS=(PROTOCOL=tcp)(HOST=188.87.135.90)(PORT=1522))
        (CONNECT_DATA=(SID=SQLCentralODBC))
        (HS=OK)
      ) 3. added the following to the listener.ora:
    LISTENER_ELMSCENTRAL =
    (ADDRESS_LIST=
          (ADDRESS=(PROTOCOL=tcp)(HOST=188.87.135.90)(PORT=1522))
    SID_LIST_LISTENER_SQLCENTRAL=
      (SID_LIST=
          (SID_DESC=
             (SID_NAME=SQLCentralODBC)
             (ORACLE_HOME=C:\oracle\product\11.1.0.7)
             (PROGRAM=hsodbc)
      )4. the listener started ok, and I validated the dsn connection and it's all ok:
    C:\Users\oracle>tnsping SQLCentralODBC
    TNS Ping Utility for 64-bit Windows: Version 11.1.0.7.0 - Production on 21-MAY-2010 15:47:12
    Copyright (c) 1997, 2008, Oracle.  All rights reserved.
    Used parameter files:
    C:\oracle\product\11.1.0.7\network\admin\sqlnet.ora
    Used TNSNAMES adapter to resolve the alias
    Attempting to contact (DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=188.87.135.90)(PORT=1522)) (CONNECT_DATA=(SID=SQLCentralODBC)) (HS
    =OK))
    OK (10 msec)
    C:\Users\oracle>5. created the db link:
    SQL> create database link LM_SQLC connect to sqlc_user identified by xxx using 'SQLCentralODBC';
    Database link created.6. Test the connection:
    SQL> select * from event@LM_SQLC;
    select * from event@LM_SQLC
    ERROR at line 1:
    ORA-28545: error diagnosed by Net8 when connecting to an agent
    Unable to retrieve text of NETWORK/NCR message 65535
    ORA-02063: preceding 2 lines from LM_SQLC
    SQL>Any ideas/help will be really appreciated.
    Thanks alot.
    Edited by: user4415740 on May 21, 2010 12:36 PM
    Edited by: user4415740 on May 21, 2010 12:52 PM

    They say "Using a 32bit DG4ODBC on a 64bit Windows operating system is NOT certified." but we do it extensively and it works just fine. You need to install a 32-bit home and create a listener for the 32-bit gateway. Only downside (aside from maintaining 2 homes) is that if you need to file an SR, you must prove that you're able to reproduce the problem when the gateway is running on a 32-bit OS. We keep a little 32-bit server around for this purpose and point our gateways to that box to reproduce issues for SR's.
    If you want to run "certified" all the time, you could leave the gateways running in Production on a 32-bit OS, but it runs considerably slower this way, and all because Oracle won't support your SR's. You have to decide if you really think you'll hit an issue that wouldn't reproduce on the true 32-bit OS and decide if it's worth the risk. We've made our decision...
    Good luck!

  • Oracle 8i Gateway Service problem for MS SQL Server 7.0

    I am installing Oracle Gateway services of oracle 8.1.7 with MS SQL Server 7.0 and want to create gateway service to access SQL Server. At some point Oracle document says :
    AT the MS-DOS prompt, enter:
    SET GTW_EXE = TGMSQL80.EXETo create a new gateway service name, enter:
    GTWSRV80 sid -CREATEI have complete Oracle 8.1.7 Release 3 pack but could not find the GTWSRV80 executable, I also do not have TGMSQL80.EXE. From where I can have these executables.
    Would some one provide solution for this problem please.
    Thanks and regards,
    Ghulam

    I am installing Oracle Gateway services of oracle 8.1.7 with MS SQL Server 7.0 and want to create gateway service to access SQL Server. At some point Oracle document says :
    AT the MS-DOS prompt, enter:
    SET GTW_EXE = TGMSQL80.EXETo create a new gateway service name, enter:
    GTWSRV80 sid -CREATEI have complete Oracle 8.1.7 Release 3 pack but could not find the GTWSRV80 executable, I also do not have TGMSQL80.EXE. From where I can have these executables.
    Would some one provide solution for this problem please.
    Thanks and regards,
    Ghulam

  • New To Oracle.. Needs Help:: Conversion from SQL Server to Oracle 11g

    I am new to Oracle 11g and badly need the conversion of SQL Server Functions to Oracle.. Sample Pasted Code not working .. end with error.. pls help
    Create Table TempT (ID1 Varchar (10),
    ID2 Varchar (10)
    CREATE OR REPLACE PACKAGE GLOBALPKG
    AS
    TYPE RCT1 IS REF CURSOR;
    TRANCOUNT INTEGER := 0;
    IDENTITY INTEGER;
    END;
    CREATE OR REPLACE FUNCTION fTempT
    i IN VARCHAR2 DEFAULT NULL
    RETURN GLOBALPKG.RCT1
    IS
    REFCURSOR GLOBALPKG.RCT1;
    BEGIN
    OPEN REFCURSOR FOR
    SELECT TT.*
    FROM TempT TT
    WHERE (fTempT.i = ''
    OR TT.ID1 = fTempT.i)
    RETURN REFCURSOR;
    END;
    CREATE OR REPLACE FUNCTION fTempTF
    i IN VARCHAR2 DEFAULT NULL
    RETURN GLOBALPKG.RCT1
    IS
    REFCURSOR GLOBALPKG.RCT1;
    BEGIN
    OPEN REFCURSOR FOR
    SELECT *
    FROM TABLE(fTempT(i))
    RETURN REFCURSOR;
    END;
    LAST FUNCTION ENDs WITH ERROR
    Error(13,7): PL/SQL: ORA-22905: cannot access rows from a non-nested table item

    2. The major purpose is to get a simplest way to create a parameterized function who can return a table like output. 2nd function has no use instead i was testing the result of First Function like thisIf you just want to select from a select, you should use a view not a function.
    1. which program is more help ful for writing and executing queries bcoz after using Query Analyzer of Microsoft It seems difficult to work on SQL Developer.
    sqlplus? If you are having difficulty learning new tools because of an old one you used, probably best to forget the old one and concentrate on learning the new one because it will be different. This goes for the database itself also.
    2. Can DMLs be used within a Function.Yes, you just can't execute the function in another SQL statement if it modifies data and this is a good thing.
    3. Can temporary tables be used within a function.Unfortunately yes, but they shouldn't be unless you are in a slowest application competition.
    5. Each Function which is a Table Function must be accompanied with Type Definitions?? its a bit longer way of doing the things than SQL ServerThat is why it is better to use views instead, is there any reason you want a select that you can select from inside a function?
    SQL Server for last 9 years thats why i refer this toolThat is not in itself a problem, if you try and do what you did in SQLServer in Oracle, that will be a problem though.

  • Connecting from oracle on windows 2008 64 bit to sql server.

    Hi,
    Oracle Server name: oraxyz
    Database: 11.2.0.4 on windows 64 Bit.
    Database home: d:\app\product\11.2.0\db_1
    SQL server: sqlabc
    I have a oracle database 11.2.0.4 on widows 2008 64 Bit on host oraxyz. I have to connect to SQL server sqlabc from this oracle database.
    So I installed gateway for windows on oraxyz server in location d:\app\product\11.2.0\gateway.
    My initdg4msql in Gaeway oracle home dg4msql\admin looks like this.
    # This is a customized agent init file that contains the HS parameters
    # that are needed for the Database Gateway for Microsoft SQL Server
    # HS init parameters
    HS_FDS_CONNECT_INFO=[sqlabc]:1433//prodsql
    HS_FDS_TRACE_LEVEL=OFF
    HS_FDS_RECOVERY_ACCOUNT=RECOVER
    HS_FDS_RECOVERY_PWD=RECOVER
    Then I created a listener in gateway oracle home as follows.
    DG4MSQL =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = TCP)(HOST = oraxyz)(PORT = 1524))
    SID_LIST_DG4MSQL =
      (SID_LIST =
        (SID_DESC =
          (SID_NAME = dg4msql)
          (ORACLE_HOME = D:\app\product\11.2.0\Gateway)
          (PROGRAM = dg4msql)
    Then in Oracle db home I created a tns alias as follows.
    dg4msql =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = oraxyz)(PORT = 1524))
        (CONNECT_DATA =
          (SID = dg4msql)
          (HS = OK)
    Then created a database link as follows
    SQL>CREATE PUBLIC DATABASE LINK tosql connect to abc identified by 123 using 'DG4MSQL';
    SQL> DESC sqlservertable@tosql gives me error
    ERROR:
    ORA-28546: connection initialization failed, probable Net8 admin error
    ORA-02063: preceding line from tosql
    Could any one please help.
    Do I have to create any ODBC connection for that?
    BR

    Not part of your problem (yet) but I always get heartburn when I see someone naming their listener as if it has a relationship to something when it doesn't.  There really is no point to naming a listener as anything but its default name of LISTENER.
    So, in your listener.ora, instead of
    DG4MSQL =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = TCP)(HOST = oraxyz)(PORT = 1524))
    SID_LIST_DG4MSQL =
      (SID_LIST =
        (SID_DESC =
          (SID_NAME = dg4msql)
          (ORACLE_HOME = D:\app\product\11.2.0\Gateway)
          (PROGRAM = dg4msql)
    Just use
    LISTENER=
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = TCP)(HOST = oraxyz)(PORT = 1524))
    SID_LIST_LISTENER =
      (SID_LIST =
        (SID_DESC =
          (SID_NAME = dg4msql)
          (ORACLE_HOME = D:\app\product\11.2.0\Gateway)
          (PROGRAM = dg4msql)

  • What is Oracle's alternative to IDENTITY Column in SQL Server/ DB2

    What is Oracle's alternative to IDENTITY Column(Auto Increment Column) in SQL Server/ DB2 ? Is Sequence and Trigger the only way out for this?
    Why is Oracle not creating anything like an Identitiy column in SQL Server?

    What is Oracle's alternative to IDENTITY Column(Auto
    Increment Column) in SQL Server/ DB2 ? Is Sequence
    and Trigger the only way out for this?Of course not, you can use in your inserts sequences as well:
    insert into blahh values (my_seq.nextval, ...) and use returniong clause to get the value back if necessary
    You can use them in insert with subselects
    insert into blah
    select my_seq.nextval, ...
    from ....
    >
    Why is Oracle not creating anything like an Identitiy
    column in SQL Server?Because they are different companies with different people and thoughts and existing mechanism is sufficient i.e. one can even argue that it is even more flexible than identity btw ;)
    Gints Plivna
    http://www.gplivna.eu

  • Equivalent of "connect by " clause in SQL Server's T/SQL to get family tree branches

    Is there any equivalent command in SQL Server's T/SQL for the command :-
    select parent, offspring from table_family start by offspring='child1' connect by parent=PRIOR offspring

    Is there any equivalent command in SQL Server's T/SQL for the command :-
    select parent, offspring from table_family start by offspring='child1' connect by parent=PRIOR offspring I had this problem some time ago. I don`t found an eqivalent on MS-SQL-server 7.0. So I wrote a T-SQL procedure wich calls itself recusively. ( I don`t have the souce-code any more ).
    I don4t know if there is an equivalent on MS-SQL-server 2000.

  • Does Oracle Data Masking pack work with MS SQL Server?

    And if so, are other OEM packs required (i.e. MS SQL Server system monitoring plug-in)?
    TIA

    Hi Martin.
    I try to resolve this problem ( sqlserver masking) but I can't found the OBE mentioned.
    You or anyone have examples about masking MS SQLServer, because in the Oracle documentation suggest that is possible but not "how do it", except the use of heterogeneous services.
    Thanks in advance.
    D.

  • Oracle ODBC driver not visible in MS SQL server 2005

    Hi all
    I am trying to export a Ms SQL Server table to Oracle and I do not see the Oracle Driver or any of my local drivers.
    Why?

    Pratik, the SQL does not seem right. BTW you can only retreive data via Deski Free hand SQL. Also try to use OLE DB connection.

  • Writing Boolean variables to MS SQL Server

    I cannot figure this out.
    In the script I'm working on, a boolean variable can be dynamic either True / False ,etc
    I cannot get the syntex correct to write this variable to a "binary" datatype column in SQL Server.
    Column name in database is Binary
    I have tried :
    UPDATE da-database
    SET Binary=@bStatus
    WHERE First=400
    da-databaseTEST
    SET Binary=&bStatus
    WHERE First=400
    da-databaseTEST
    SET Binary=bStatus
    WHERE First=400
    But if I use
    da-databaseTEST
    SET Binary=1
    WHERE First=400
    It sets the field to true i.e, Works correctly.  Just get get it going with a variable.

    it is UCCX and
    I'm having issues writing to a database doing any variable substitution.
    I gave up on the boolean and decided to use just strings but hitting Null.Pointer Exceptions even though (IMHO) things are correct.
    Is there a particular varaible type that I should defining in SQL that works "best" with the java beans and IPCC?

  • Convert Oracle "connect by level 10" into MS SQL server 2005

    I want to convert oracle "SELECT LEVEL R FROM CONNECT BY LEVEL <=10" my bottom requirement is  get 1 to 10 as a dynamic table inside a query.
    Ex: Select id, name, R from names N, (1,2,3,4,5,6,7,8,9,10) R WHERE id < 1000 
    If any one know something regarding this please reply me.
    Thx,
    Buddhika

    Hi Buddhika Jayawardhane ,
    Have you sold your problem? I have the same issue to convert from Oracle into SQL Server:
    SELECT all_steps.to_step_id step_id, rownum step_order
    FROM (
    SElECT 0 from_step_id, steps.step_id to_step_id
    FROM steps
    WHERE steps.is_root = 1
    UNION
    SElECT step_transitions.from_step_id, step_transitions.to_step_id
    FROM step_transitions
    ) all_steps
    CONNECT BY all_steps.from_step_id = PRIOR all_steps.to_step_id
    START WITH all_steps.from_step_id = 0
    Please help me find information how to make it!
    Thanks in advance,
    cores

  • Equivalent datatype in Oracle for datetime of SQL Server

    Hello Everyone,
    I'm very much new to Oracle. I have been working with SQL Server since 3yrs. Currently I'm working with Oracle 11g.
    What is the equivalent datatype in oracle for datetime in sql server with which has the format YYYY-MM-DD HH:MM:SS?
    I tried with timestamp and date which didnt solve my prob.... Please help me in using the equivalent datatype for the format provided above...
    Regards,
    Bhanu Yalamanchi.

    Oracle date format can be anything you want, either by default at the session level or preferably explicitly using to_char and a format mask.
    Format masks are documented here.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/sql_elements004.htm#CDEHIFJA
    SQL> create table t (d date);
    Table created.
    SQL> insert into t values (sysdate);
    1 row created.
    SQL> select * from t;
    D
    19-JUL-11
    SQL> alter session set nls_date_format = 'YYYY-MM-DD HH:MI:SS';
    Session altered.
    SQL> select * from t;
    D
    2011-07-19 08:27:59
    SQL> select d, to_char(d, 'YYYY-MM-DD'), to_char(d,'Day') from t;
    D                   TO_CHAR(D, TO_CHAR(D
    2011-07-19 08:27:59 2011-07-19 Tuesday
    SQL> alter session set nls_date_format = 'DD-MON-YY';
    Session altered.
    SQL> select d, to_char(d, 'YYYY-MM-DD HH24:MI:SS') from t;
    D         TO_CHAR(D,'YYYY-MM-
    19-JUL-11 2011-07-19 08:27:59

  • Looking for the oracle equivalent of T-SQL 'SELECT TOP n'

    Hi,
    I'm looking for the Oracle equivalent of T-SQL 'SELECT TOP n'
    and can't find any. There is SAMPLE(n) function but it supposed
    to pick up random values and I'm not sure if it's possible to
    make it select top values. Please help 8-)
    Thanx

    Hi Marina.
    Oracle does not have a functionality like SQL Server for TOP
    selection. The ROWNUM option should be used with great care and
    you may get unreliable results.
    Try looking at Metalink
    Doc ID: 291065.999
    Doc ID: 267329.999
    - They discuss this issue, and solutions.

Maybe you are looking for

  • Unable to extract data from R/3 into BW 3.5

    I have just started learning BW. I am currently trying to upload data from R/3 into BW. I have tried uploading data into InfoCube , ODS, InfoObjects from R/3 and in all cases I am getting error messages. Please shed some light as the what am doing wr

  • CR XI R2: Database logon failed. Database Vendor Error Code: 1005

    Hi: I am trying to incorporate Crystal Reports XI R2 with in-house application - Windows platform, Oracle9i, Websphere Studio Application Development 5.1, and JVM 1.4.2 with OCI8 driver and JNDI connection. I am not getting any error while running it

  • Rounding Up

    i've searched the forum and i tried google, but i can't find out how to make it so that even if it's mathematically correct to round down, it rounds up. ie: lets say the resulting number is 2.6, that gets round up to 3, but i need it to round up to 3

  • M item category in KKPAN

    Hi, how can i get the M item  category in KKPAN, all i see is V, if i give M its not taking from the drop down, how can i fix to show up M, in KKPAN for  purchased items. Thanks

  • Cons Group & Unit Display in Monitor

    With the upgrade to EP3 the cons groups and units name displayed in the monitor are the short description instead of the long description as was previously the case. It would be most appreciated if you would please suggest ways to change the names di