下面语句报缺少关键字:SQL_TEXT := 'INSERT INTO ' || BLANKS || ' (RSERIAL,TYPE,CONTENT) SELECT ROWNUM,2,ROWNUM||''^''||CONTENT FROM( SELECT DISTINCT B.NO, B.NO||''^''||B.NAME||''^''||B.SPECS||''^''||B.MTLMARK||''^''||C.PBNUM||''×''||D.SL||C.UNIT||''^''||C.DSNWEIGHT||''^''|| CASE WHEN C.SSSYB IN (''02-通风机事业'',''03-鼓风机事业'',''04-透平事业部事业'' )THEN B.DWSPECS WHEN C.SSSYB =''05-泵业事业部'' THEN C.HGZXH ||''^''||C.SMEMO AS CONTENT FROM GTMP_BOM_TREE A,MPART B ,SIPM10 C ,SIPM9 D ,SIPM9_OBJOF F WHERE A.CID=B.ID AND B.WKAID<>''3'' AND B.DEL=0 AND C.WKAID<>''3'' AND C.DEL=0 AND D.WKAID<>''3'' AND D.DEL=0 AND C.ID=F.ITEMID2 AND F.ITEMID1=D.ID AND D.ID=''' || OBJID || ''' AND C.ZXSX<>''机床衣'' ORDER BY B.NO )'; EXECUTE IMMEDIATE SQL_TEXT;
时间: 2023-08-20 12:04:17 浏览: 153
matlab_常用函数汇总
这个 SQL 语句缺少 INSERT INTO 后面的表名,BLANKS 值也没有给出,需要补充完整。同时,最后一行的 EXECUTE IMMEDIATE 也需要加上异常处理,以防止出错时程序崩溃。可以改为如下代码:
```
DECLARE
SQL_TEXT VARCHAR2(4000);
BEGIN
SQL_TEXT := 'INSERT INTO 表名(RSERIAL, TYPE, CONTENT) ' || BLANKS ||
'SELECT ROWNUM, 2, ROWNUM || ''^'' || CONTENT FROM (
SELECT DISTINCT B.NO, B.NO || ''^'' || B.NAME || ''^'' || B.SPECS || ''^'' || B.MTLMARK || ''^'' || C.PBNUM || ''×'' || D.SL || C.UNIT || ''^'' || C.DSNWEIGHT || ''^'' ||
CASE WHEN C.SSSYB IN (''02-通风机事业'',''03-鼓风机事业'',''04-透平事业部事业'' ) THEN B.DWSPECS
WHEN C.SSSYB =''05-泵业事业部'' THEN C.HGZXH ||''^''||C.SMEMO
END AS CONTENT
FROM GTMP_BOM_TREE A, MPART B, SIPM10 C, SIPM9 D, SIPM9_OBJOF F
WHERE A.CID = B.ID AND B.WKAID <> ''3'' AND B.DEL = 0
AND C.WKAID <> ''3'' AND C.DEL = 0
AND D.WKAID <> ''3'' AND D.DEL = 0
AND C.ID = F.ITEMID2 AND F.ITEMID1 = D.ID AND D.ID = ' || OBJID || ' AND C.ZXSX <> ''机床衣''
ORDER BY B.NO
)';
BEGIN
EXECUTE IMMEDIATE SQL_TEXT;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('SQL 执行出错:' || SQLERRM);
END;
END;
```
阅读全文