Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.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_Plsql - Fatal编程技术网

尝试执行嵌套循环时,SQL语句无效

尝试执行嵌套循环时,SQL语句无效,sql,oracle,plsql,Sql,Oracle,Plsql,我正在编写一个plsql脚本,该脚本根据一些条件分配一个指标。我尝试使用2个嵌套for循环来实现这一点。然而,当我尝试执行时,我在第2行得到一条错误的无效SQL语句。我看了一遍又一遍,没有发现任何问题。感谢您的帮助 begin for rec in (select prgm_id, (prgm_cntl_pct * cntl_count) as cntl from tmp_prgm_cntl) loop for rec2 in (select * from tmp_cust_pop tcp

我正在编写一个plsql脚本,该脚本根据一些条件分配一个指标。我尝试使用2个嵌套for循环来实现这一点。然而,当我尝试执行时,我在第2行得到一条错误的无效SQL语句。我看了一遍又一遍,没有发现任何问题。感谢您的帮助

begin
for rec in (select prgm_id, (prgm_cntl_pct * cntl_count) as cntl from tmp_prgm_cntl) loop
  for rec2 in (select * from tmp_cust_pop tcp where tcp.prgm_id = rec.prgm_id and rownum <= rec.cntl order by tcp.rand_num) loop 
  insert into fact_cust_trgt_pop (fact_cust_trgt_pop_id, stg_prgm_cust_trgt_pop_id, cust_nbr, cust_id,
                              prgm_id, prgm_name, prgm_cntl_ind, cmpg_cntl_ind, cust_open_dt, cre_dt, updt_dt)
(select
  (select dmbs_random.value(1,200)from dual) as fact_cust_trgt_pop_id,
  rec2.stg_cust_trgt_pop_id,
  sctp.cust_nbr,
  sctp.cust_id,
  sctp.prgm_id,
  sctp.prgm_name,
  1 as prgm_cntl_ind,
  (select (dmbs_random.value(0,2)) case when <=1 then 'a' else 'b' as cmpg_cntl_ind end from dual) as cmpg_cntl_ind, 
  sctp.prgm_cust_open_dt,
  sctp.cre_dt,
  sctp.updt_dt
 from 
  stg_cust_trgt_pop sctp
  join sc45437.stg_cust_trgt_pop sctp
  on
  sctp.stg_cust_trgt_pop_id = tcp.stg_cust_trgt_pop_id); 
 end loop;
end loop;
end;

1选择选择dmbs_随机。值1200…-缺少列列表。2如果从dual中选择dmbs_random.value0,2,则您似乎试图使用动态PL/SQL。但是您正在构造的PL/SQL块是不完整的,例如,没有开始和结束。但是,更重要的是,似乎没有必要首先使用动态PL/SQL。除非在简化的示例中有一些不明显的巨大优势,否则在选择dmbs_random.value0,2时只需使用纯静态PL/SQL.case。当您摆脱立即检查时,请小心地执行立即检查,您将摆脱所有不需要的引用,如以下case语句:case when dmbs_random.value0,2