我有这个pl / sql代码块,
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;
我无法弄清楚为什么在运行此块时会抛出以下错误
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:
答案 0 :(得分:3)
SQL * Plus命令
set serveroutput ON;
clear screen;
PL / SQL阻止
您需要将变量设为sSql
,同时我更正了作业中的extra single quote
!
还为CLOSE
光标添加了块!
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;
/
答案 1 :(得分:1)
为不存在的变量sql
分配值:
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