Oracle
 sql >> база данни >  >> RDS >> Oracle

Еквивалент на функцията R cbind() в Oracle?

В Oracle трябва изрично да дефинирате някаква стойност, за да получите подредени данни; без това можете да имате различни резултати всеки път, когато стартирате заявка.

С вашите данни това:

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)

дава:

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

Без изрично подреждане, например това

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)

дава

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


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Регулярният израз на Oracle замества множество срещания на низ, ограден със запетаи

  2. Как трябва да сменя своя sql, за да получа това, което искам в този случай?

  3. ActiveMQ 5.8:Не може да се зареди клас JDBC драйвер „oracle.jdbc.driver.OracleDriver“

  4. Причинено от:java.lang.ClassNotFoundException:oracle.jdbc.OracleDriver

  5. Грешка в изхода на SQL Fiddle