简体   繁体   中英

Need support to convert SQL Server query to Oracle

The TableC and TableB have multiple records, I want select multiple records from TableB and one record from TableC which is working in SQL Server. But actual requirement in Oracle database where it's not working. Please help to convert below SQL Server query to Oracle.

Select 
     Data-A,
     Data-B,
    (Select Top 1 DATA-C from
     TableC Where TableC.SourcePtr=Tabbleb.Rkey order by Step Desc) as Data-C
From TableA,
     TableB
Where TableA.Source_PTR =TableB.Rkey 

You can use ROWNUM :

Select 
     Data-A,
     Data-B,
     (Select * from (
        (
            Select data-C from TableC 
            Where TableC.SourcePtr=Tabbleb.Rkey order by Step Desc
        )
      where rownum = 1 ) as Data-C
From TableA,
     TableB
Where TableA.Source_PTR =TableB.Rkey 

or you can use FETCH NEXT N ROWS ONLY :

Select 
     Data-A,
     Data-B,
     (Select DATA-C from TableC 
      Where TableC.SourcePtr=Tabbleb.Rkey order by Step Desc
      FETCH NEXT 1 ROWS ONLY) as Data-C
From TableA,
     TableB
Where TableA.Source_PTR =TableB.Rkey 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM