【问题标题】:Left join - SAS and oracle左连接 - SAS 和 oracle
【发布时间】:2017-05-30 18:27:22
【问题描述】:

我正在尝试从我的 SAS 工作 libref 中的表进行左连接并从 Oracle 中提取,但它给出了错误消息。

这是我的代码:

PROC SQL;
connect to oracle(user=&usuario pass=&pass_dwhprd path='@dtm');
create table base_rateio1 (compress=yes reuse=yes) as
select B.* from connection to oracle
(select 
       A.*,
       substr(B.exem_cod_sog_scv,3,4)  projeto

  from       work.BASE_KPI3_2     A
  left join  exo_ing_ems@lkdwh    B 

where  exem_cod_cia >= 1
   and exem_cod_idt_fil >= 1
   and A.apolice  = B.exem_apo_num
   and A.contrato = B.exem_ctrs_cod
   and A.filial   = B.exem_cod_idt_fil
   and A.cod_cia  = B.exem_cod_cia
   and B.exem_ems_cod = 1
)
as t1;
disconnect from oracle;
quit;

这是错误信息:

 ERROR: ORACLE prepare error: ORA-00905: missing keyword. SQL statement: select A.*, substr(B.exem_cod_sog_scv,3,4) projeto from 
       work.BASE_KPI3_2 A, left join exo_ing_ems@lkdwh B where exem_cod_cia >= 1 and exem_cod_idt_fil >= 1 and A.apolice = 
       B.exem_apo_num and A.contrato = B.exem_ctrs_cod and A.filial = B.exem_cod_idt_fil and A.cod_cia = B.exem_cod_cia and 
       exem_ems_cod = 1.

我真的不知道是什么问题

【问题讨论】:

  • 您不能在连接语句中使用 SAS 工作表。您需要进行隐式传递或将 SAS 表移动到 Oracle,然后使用连接语句。
  • @Kiran 没有其他方法可以做到这一点吗?我无权将 SAS 表移至 Oracle。这就是我尝试这个左连接的原因。
  • 那么您没有进行隐式传递。请参阅下面答案中的第三步
  • 从上面...您缺少用于左连接的ON 语句。基于错误:ORA-00905: missing keyword

标签: oracle sas left-join


【解决方案1】:

connect 语句在 oracle 中执行所有操作。因此,您的查询将无法在 connect 语句中工作。你有两个选择。将 SAS 表移动到 Oracle,然后按照接下来的两个步骤进行连接

proc sql;
create table oratable.tablename as
select *
from sastable.tablename;
quit;

然后在查询中使用上表

  proc sql;
    connect to oracle (user=&myid orapw=&mypwd path="&mydb");
    execute ( use your logic here) by oracle; 
    disconnect from oracle;
    quit;

如果上述事情是不可能的,你必须做这样的事情。

 libname oratable oracle user=user password=password path=path; 

 proc sql;
    create table oratable.tablename as
    select *
    from sastable.tablename left join oratable.tablename
    on yourcolumns
    quit;

【讨论】:

  • 可能想在此处明确提及/显示libname 语法,以使其更清晰。
  • Joe,也根据您的建议添加了 libname 语法
【解决方案2】:

您正在使用 ANSI 命名法来说明您的 LEFT JOIN 子句,因此您应该使用 ON 谓词来建立两个表之间的关系,例如:

select B.* from connection to oracle
(select 
       A.*,
       substr(B.exem_cod_sog_scv,3,4)  projeto

  from       work.BASE_KPI3_2     A
  left join  exo_ing_ems@lkdwh    B ON A.apolice  = B.exem_apo_num
                                    and A.contrato = B.exem_ctrs_cod
                                   and A.filial   = B.exem_cod_idt_fil
                                   and A.cod_cia  = B.exem_cod_cia
                                   and B.exem_ems_cod = 1

where  exem_cod_cia >= 1
   and exem_cod_idt_fil >= 1
)

我不知道 'exem_cod_cia' 和 'exem_cod_idt_fil' 字段在哪个表中,所以如果它们在 B 中,它们也可以放在 'ON' 谓词中,否则你可以将它们留在那里。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-31
    • 1970-01-01
    • 2016-10-02
    • 1970-01-01
    • 2020-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多