SQL查询以添加多个列

问题描述 投票:0回答:1

我想在每次执行命令时添加一个列名EntityId,并循环检查是否添加了该列。如果是,则将生成下一列而没有任何重复。请看我的代码。我没有得到实际的o / p。

BEGIN
           Declare @maxEntityID int;
                 SET @maxEntityID = (SELECT MAX(EntityID) FROM [Location_2]);        
                 aNumber=1;
                 LOOP
SET FEEDBACK OFF
SET TERMOUT OFF
SET WRAP ON
SET ECHO OFF
SET LINESIZE 1300
SET PAGESIZE 0
SET VERIFY OFF
SET TRIMSPOOL ON
spool D:\result\@a.txt
set heading off long 2000
select xmlelement("CISDocument,
xmlelement("ApiHeader",xmlforest(OperationName AS "OperationName")),
xmlelement("Entity",
xmlelement("DistributionCentre",
xmlelement("Address",xmlforest("Street" AS "Street"))) from Location_2;
spool off;
           a =a+1;
           EXIT WHEN a>maxEntityID;
           END LOOP;
END
oracle automated-tests oracle-sqldeveloper plsqldeveloper
1个回答
0
投票

您的代码中有很多错误。看起来您正在混合使用SQL Server Transact SQL和Oracle PL / SQL。

在PL / SQL DECLARE部分中是之前 BEGIN块部分。

Oracle变量标识符不能以@开头:

SQL> declare  @id int;
  2  begin
  3   @id = 1;
SP2-0310: unable to open file "id.sql"
  3  end;
  4  /
declare  @id int;
         *
ERROR at line 1:
ORA-06550: line 1, column 10:
PLS-00103: Encountered the symbol "@" when expecting one of the following:
begin function pragma procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete
exists prior

SET是无效的PL / SQL分配:

SQL> declare  id int;
  2  begin
  3   set id = 1;
  4  end;
  5  /
 set id = 1;
     *
ERROR at line 3:
ORA-06550: line 3, column 6:
PL/SQL: ORA-00922: missing or invalid option
ORA-06550: line 3, column 2:
PL/SQL: SQL Statement ignored


SQL> 

Etc ...

© www.soinside.com 2019 - 2024. All rights reserved.