sql >> Database teknologi >  >> RDS >> Oracle

Ækvivalent af R cbind() funktion i Oracle?

I Oracle skal du eksplicit definere en værdi for at få bestilte data; uden det, kunne du få forskellige resultater, hver gang du kører en forespørgsel.

Med dine data, dette:

WITH table1 AS (SELECT 1 rn, '1' col1 FROM DUAL UNION SELECT 2 rn, '2' col1 FROM DUAL UNION SELECT 3 rn, 'NO_PATTERN' col1 FROM DUAL UNION SELECT 4 rn, 'RANDOM_STUFF' col1 FROM DUAL), table2 AS (SELECT 1 rn, 'aaa' col2 FROM DUAL UNION SELECT 2 rn, '4' col2 FROM DUAL UNION SELECT 3 rn, 'qwewqeq' col2 FROM DUAL UNION SELECT 4 rn, 'UUUUUU' col2 FROM DUAL) SELECT col1, col2, t1.rn from (select row_number() over (order by rn) as rn, col1 from table1 ) t1 inner join (select row_number() over (order by rn) as rn, col2 from table2 ) t2 on (t1.rn = t2.rn)

giver:

COL1         COL2            RN
------------ ------- ----------
1            aaa              1
2            4                2
NO_PATTERN   qwewqeq          3
RANDOM_STUFF UUUUUU           4
 

Uden en eksplicit ordre, f.eks. dette

WITH table1 AS
         (SELECT '1'            col1 FROM DUAL UNION
          SELECT '2'            col1 FROM DUAL UNION
          SELECT 'NO_PATTERN'   col1 FROM DUAL UNION
          SELECT 'RANDOM_STUFF' col1 FROM DUAL),
     table2 AS
         (SELECT 'aaa'     col2 FROM DUAL UNION
          SELECT '4'       col2 FROM DUAL UNION
          SELECT 'qwewqeq' col2 FROM DUAL UNION
          SELECT 'UUUUUU'  col2 FROM DUAL)
SELECT col1, col2, t1.rn
from (select  rownum as rn, col1 from table1 ) t1
       inner join 
     (select rownum as rn, col2 from table2 ) t2
     on (t1.rn = t2.rn)
 

giver

COL1         COL2            RN
------------ ------- ----------
1            4                1
2            UUUUUU           2
NO_PATTERN   aaa              3
RANDOM_STUFF qwewqeq          4
 


  1. Returner alle fremmednøgler &CHECK-begrænsninger i en SQL Server-database (T-SQL-eksempler)

  2. Kør batchfil med psql-kommando uden adgangskode

  3. upload af billeder til server i foråret MVC og lagring af reference i mysql database

  4. ORA-06502:PL/SQL:numerisk eller værdifejl:tegnstrengbuffer for lille - Udfører ved hjælp af OCI-interface