Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试使用大型SQL查询_Sql_Oracle_Excel_Vba - Fatal编程技术网

尝试使用大型SQL查询

尝试使用大型SQL查询,sql,oracle,excel,vba,Sql,Oracle,Excel,Vba,我尝试使用白色大型SQL查询,如下所示: insert into R7810TEST (select 1111111 , 111111 , 1111111 ,'ORG' ,R401.ZIHUI_BAAL_POLISA ,8990 ,'ID' ,R401.ZIHUI_M_RASHI , R401.M_POLISA ,R440.M_SOCHEN , 201507 ,'ORG' , R401.ZIHUI_BAAL_POLISA ,'RTP' , 'CUR' , '1', '*' ,

我尝试使用白色大型SQL查询,如下所示:

insert into R7810TEST 
   (select 1111111 ,  111111 , 1111111 ,'ORG' ,R401.ZIHUI_BAAL_POLISA ,8990  ,'ID' ,R401.ZIHUI_M_RASHI , R401.M_POLISA  ,R440.M_SOCHEN , 201507 ,'ORG'  , R401.ZIHUI_BAAL_POLISA  ,'RTP' , 'CUR'  , '1', '*' ,0  ,10000.00  ,0.00 , 0.00 , 0.00, 0.00, 0.00 , 0.00,0.00, 0.00 , r430.hf_oved_tagmulim_45 ,r430.hf_mavid_tagmulim , r430.hf_mavid_pizuim_mukar ,  0.00, r430.hf_mavid_chelef, r430.hf_oved_shonot, r430.hf_mavid_shonot , r430.hf_oved_tagmulim_47 ,'MNG', 0.00 , 0.00 ,0.00 ,0.00 , '*' , to_date ('20150701', 'yyyymmdd'), R401.ZIHUI_BAAL_POLISA, r400.sug_polisa, to_date ('20150701', 'yyyymmdd'),'CHI', '12' , 0, 0 ,'0', to_date ('19000101', 'yyyymmdd')  
from r400 R400 ,r401 R401 ,r430 r430 ,r440 r440
where r400.m_polisa = r401.m_polisa
and r401.m_polisa = r430.m_polisa
and r430.m_polisa= r440.m_polisa
and r401.tr_rishum in (select max(aa.tr_rishum) from r401 aa where aa.m_polisa = r401.m_polisa)
and r430.tr_rishum in (select max(aa.tr_rishum) from r430 aa where aa.m_polisa = r430.m_polisa)
and r440.tr_rishum in (select max(aa.tr_rishum) from r440 aa where aa.m_polisa = r440.m_polisa)
and r401.status_rashi = 10
--and r401.status_rashi in (30,35)
----and r401.status_rashi in (90)
--and r401.status_rashi = 20
and r400.sug_polisa in ('1','3','5','7')
and r400.sug_hishtatfut <>0
and r400.sug_hazmada <>0
and r400.m_polisa IN (XXXXX));
insert into R7810TEST
( column1, column2, ...etc)
select 1111111 ,  111111 , 1111111 ,'ORG' ...etc

我从SQL中得到一个例外,我通过Excel使用Oracle和vba,我认为这个字符串太大,所以它不起作用,SQL得到了查询的一部分。如何在vba代码中使用此查询?

您没有说明错误是什么,但看起来您的insert…select格式不正确。作为一种良好做法,您应该在select子句之前指定要插入的列,并删除select子句周围的括号。大概是这样的:

insert into R7810TEST 
   (select 1111111 ,  111111 , 1111111 ,'ORG' ,R401.ZIHUI_BAAL_POLISA ,8990  ,'ID' ,R401.ZIHUI_M_RASHI , R401.M_POLISA  ,R440.M_SOCHEN , 201507 ,'ORG'  , R401.ZIHUI_BAAL_POLISA  ,'RTP' , 'CUR'  , '1', '*' ,0  ,10000.00  ,0.00 , 0.00 , 0.00, 0.00, 0.00 , 0.00,0.00, 0.00 , r430.hf_oved_tagmulim_45 ,r430.hf_mavid_tagmulim , r430.hf_mavid_pizuim_mukar ,  0.00, r430.hf_mavid_chelef, r430.hf_oved_shonot, r430.hf_mavid_shonot , r430.hf_oved_tagmulim_47 ,'MNG', 0.00 , 0.00 ,0.00 ,0.00 , '*' , to_date ('20150701', 'yyyymmdd'), R401.ZIHUI_BAAL_POLISA, r400.sug_polisa, to_date ('20150701', 'yyyymmdd'),'CHI', '12' , 0, 0 ,'0', to_date ('19000101', 'yyyymmdd')  
from r400 R400 ,r401 R401 ,r430 r430 ,r440 r440
where r400.m_polisa = r401.m_polisa
and r401.m_polisa = r430.m_polisa
and r430.m_polisa= r440.m_polisa
and r401.tr_rishum in (select max(aa.tr_rishum) from r401 aa where aa.m_polisa = r401.m_polisa)
and r430.tr_rishum in (select max(aa.tr_rishum) from r430 aa where aa.m_polisa = r430.m_polisa)
and r440.tr_rishum in (select max(aa.tr_rishum) from r440 aa where aa.m_polisa = r440.m_polisa)
and r401.status_rashi = 10
--and r401.status_rashi in (30,35)
----and r401.status_rashi in (90)
--and r401.status_rashi = 20
and r400.sug_polisa in ('1','3','5','7')
and r400.sug_hishtatfut <>0
and r400.sug_hazmada <>0
and r400.m_polisa IN (XXXXX));
insert into R7810TEST
( column1, column2, ...etc)
select 1111111 ,  111111 , 1111111 ,'ORG' ...etc

我可以看到一些可能发生的事情。没有R7810测试的DDL很难说,但我有2.5个猜测

SQL中的最后一条语句表示XXXXX中的r400.m_polisa。这似乎不是强类型。这是一个占位符,还是真正的SQL?如果XXXXX是字符串,则需要引号。如果它应该是一个数字,那么。。。你知道的。如果它是其中一个表中的一个字段,那么我想这没关系,但如果是这样的话,它是一个奇怪的构造。 VBA不能很好地处理大型连接。你没有列出你的VBA代码,但我可以很容易地看到它吐在和你一样大的字符串上。要解决这个问题,可以将串联分解为多个步骤。虽然SQL实际上似乎有平衡的圆括号,但select语句周围的圆括号是不必要的,但当您试图用VBA字符串包装它时,不难忽略一些小的内容。 第2项的后续内容——同样是VBA连接,缺少空格这样简单的东西可能会破坏您最好的SQL。例如: 例如:

sql = "select one, two, three" & _
      "from foo"
无意中变成:

select one, two, threefrom foo
第2点的示例:

cmd.CommandText = _
    "insert into R7810TEST" & _
    "select" & _
    "   1111111 ,  111111 , 1111111 ,'ORG' ,R401.ZIHUI_BAAL_POLISA ,8990  ,'ID' ," & _
    "   R401.ZIHUI_M_RASHI , R401.M_POLISA  ,R440.M_SOCHEN , 201507 ,'ORG'  ," & _
    "   R401.ZIHUI_BAAL_POLISA  ,'RTP' , 'CUR'  , '1', '*' ,0  ,10000.00  ," & _
    "   0.00 , 0.00 , 0.00, 0.00, 0.00 , 0.00,0.00, 0.00 ," & _
    "   r430.hf_oved_tagmulim_45 ,r430.hf_mavid_tagmulim ," & _
    "   r430.hf_mavid_pizuim_mukar ,  0.00, r430.hf_mavid_chelef," & _
    "   r430.hf_oved_shonot, r430.hf_mavid_shonot , r430.hf_oved_tagmulim_47 ," & _
    "   'MNG', 0.00 , 0.00 ,0.00 ,0.00 , '*' , to_date ('20150701', 'yyyymmdd')," & _
    "   R401.ZIHUI_BAAL_POLISA, r400.sug_polisa, to_date ('20150701', 'yyyymmdd')," & _
    "   'CHI', '12' , 0, 0 ,'0', to_date ('19000101', 'yyyymmdd') "

 cmd.CommandText = cmd.CommandText & _
    "from r400 R400 ,r401 R401 ,r430 r430 ,r440 r440 " & _
    "where r400.m_polisa = r401.m_polisa " & _
    "and r401.m_polisa = r430.m_polisa " & _
    "and r430.m_polisa= r440.m_polisa " & _
    "and r401.tr_rishum in (select max(aa.tr_rishum) " & _
         "from r401 aa where aa.m_polisa = r401.m_polisa) " & _
    "and r430.tr_rishum in (select max(aa.tr_rishum) " & _
         "from r430 aa where aa.m_polisa = r430.m_polisa) " & _
    "and r440.tr_rishum in (select max(aa.tr_rishum) " & _
         "from r440 aa where aa.m_polisa = r440.m_polisa) " & _
    "and r401.status_rashi = 10 " & _
    "and r400.sug_polisa in ('1','3','5','7') " & _
    "and r400.sug_hishtatfut <>0 " & _
    "and r400.sug_hazmada <>0 " & _
    "and r400.m_polisa IN ('XXXXX')"
当有疑问时,在SQL中自由使用空格


临别镜头-如果这没有帮助,请张贴您的表的DDL。它可能会提示您出了什么问题。

您需要告诉我们您遇到了什么错误。此查询远不是太大。请删除括号,插入R7810TEST select…:说明:ORA-00907:缺少右括号:字符串:但是如果我看到了qurey,那么不是所有qurey都在strinfg中,并且sql认为rison缺少右括号。请重新表述您的问题?这很难理解。例如,符号“.”、“!”、“?”你不仅看起来不错。他们正在大量提高可读性和可理解性。谢谢你…我在PL/SQL中这样运行这个查询,当我把它放在vba中时,它运行得非常好,所以qurey是goodORA-00936:缺少表达式这是一个错误,我在插入字符串virble后得到了一个字符串:插入R7810TEST选择7349926.89865094580081.0844081646215666.96627682,'ORG',R401.ZIHUI_BAAL_POLISA,8990,'ID',R401.ZIHUI_M_RASHI,775932,R440.M_SOCHEN,1,'ORG',R401.ZIHUI_BAAL_POLISA,'RTP','1','*',8,1,1,1,1,1,1,1,不是所有的字符串都进入字符串变量R401。ZIHUI__BAAL_POLISA,'RTP','1',将给您一个错误,因为这两个逗号之间没有任何区别。您用于构造此查询的代码中似乎存在错误。