首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >这个PL/SQL有什么问题

这个PL/SQL有什么问题
EN

Stack Overflow用户
提问于 2014-02-28 22:44:57
回答 2查看 1.5K关注 0票数 0

我有这个pl/sql代码块,

代码语言:javascript
复制
set serveroutput 
clear screen;

DECLARE
  TYPE    recPriceList is Record(comno varchar2(3),t$cpls varchar2(6),t$dsca varchar(100), Customers int,minExpiry varchar2(20),groupCount int,undefGroups int);
  comno   VARCHAR2(6)   :='010';
  sSql    VARCHAR2(1000):=' ';
  c      sys_refcursor;
  r       recPricelist;
BEGIN

  sql:=q'[select distinct  lpad('010',3,'0'), t$cpls cpls,t$dsca,count(t$cuno),null  Customers,null,null  
        from baan.ttccom010010 c  
        join baan.ttcmcs034010 p on c.t$cpls = p.t$cplt  
        where trim(t$cpls) is not null    
        group by T$CPLS,T$DSCA  order by t$cpls']';

  OPEN c FOR sSql ;
  LOOP
    FETCH c INTO r;
    DBMS_OUTPUT.PUT_LINE(r.comno||' | '||r.t$cpls|| ' dsca='|| r.t$dsca);
    EXIT   WHEN c%notfound;
  END LOOP;
END;

我不明白为什么当我运行这个代码块时会抛出下面的错误

代码语言:javascript
复制
SQLPLUS command failed - not enough arguments Error starting at line : 5 in command - DECLARE   TYPE    recPriceList is Record(comno
varchar2(3),t$cpls varchar2(6),t$dsca varchar(100), Customers
int,minExpiry varchar2(20),groupCount int,undefGroups int);   comno  
VARCHAR2(6)   :='010';   sSql    VARCHAR2(1000):=' ';   c     
sys_refcursor;   r       recPricelist; BEGIN

  sql:=q'[select distinct  lpad('010',3,'0'), t$cpls
cpls,t$dsca,count(t$cuno),null  Customers,null,null  
        from baan.ttccom010010 c  
        join baan.ttcmcs034010 p on c.t$cpls = p.t$cplt  
        where trim(t$cpls) is not null    
        group by T$CPLS,T$DSCA  order by t$cpls']';
       OPEN c FOR sSql ;   LOOP
    FETCH c INTO r;
    DBMS_OUTPUT.PUT_LINE(r.comno||' | '||r.t$cpls|| ' dsca='|| r.t$dsca);
    EXIT   WHEN c%notfound;   END LOOP; END; Error report - ORA-06550: line 9, column 6: PLS-00103: Encountered the symbol "=" when expecting
one of the following:

   %
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:
EN

回答 2

Stack Overflow用户

发布于 2014-02-28 22:50:07

SQL*Plus命令

代码语言:javascript
复制
set serveroutput ON; 
clear screen;

SQL/

您需要将变量设置为sSql,我还更正了赋值中的extra single quote

增加了块,以CLOSE的光标以及!

代码语言:javascript
复制
DECLARE
  TYPE    recPriceList is Record(comno varchar2(3),t$cpls varchar2(6),t$dsca varchar(100), Customers int,minExpiry varchar2(20),groupCount int,undefGroups int);
  comno   VARCHAR2(6)   :='010';
  sSql    VARCHAR2(1000):=' ';
  c      sys_refcursor;
  r       recPricelist;
BEGIN

  sSql := q'[select distinct  lpad('010',3,'0'), t$cpls cpls,t$dsca,count(t$cuno),null  Customers,null,null  
        from baan.ttccom010010 c  
        join baan.ttcmcs034010 p on c.t$cpls = p.t$cplt  
        where trim(t$cpls) is not null    
        group by T$CPLS,T$DSCA  order by t$cpls]';

  OPEN c FOR sSql ;
  LOOP
    FETCH c INTO r;
    DBMS_OUTPUT.PUT_LINE(r.comno||' | '||r.t$cpls|| ' dsca='|| r.t$dsca);
    EXIT   WHEN c%notfound;
  END LOOP;
  CLOSE c;
END;
/
票数 3
EN

Stack Overflow用户

发布于 2014-02-28 22:52:59

为不存在的变量sql赋值

代码语言:javascript
复制
  sql:=q'[select distinct  lpad('010',3,'0'), t$cpls cpls,t$dsca,count(t$cuno),null  Customers,null,null  
        from baan.ttccom010010 c  
        join baan.ttcmcs034010 p on c.t$cpls = p.t$cplt  
        where trim(t$cpls) is not null    
        group by T$CPLS,T$DSCA  order by t$cpls']';

只需将变量名更改为sSql

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22098256

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档