简体   繁体   English

SAP HANA 过程动态 SQL 选择到变量:不工作

[英]SAP HANA Procedure Dynamic SQL Select Into Variable: Not Working

Any ideas on how to use spatial functions in either a procedure or a calculation view?关于如何在过程或计算视图中使用空间函数的任何想法? I cannot use a table function, as I need a cursor.我不能使用表函数,因为我需要一个游标。 Please see issues below:请参阅以下问题:

I tried dynamic SQL in a stored procedure with select into (Doesn't allow into): (About three months back it did work, but now cannot activate?) This blog says it should work: https://blogs.sap.com/2017/04/18/sap-hana-2.0-sps-01-new-developer-features-database-development/我在存储过程中尝试使用 select into(不允许进入)动态 SQL:(大约三个月前它确实有效,但现在无法激活?)此博客说它应该有效: https : //blogs.sap.com /2017/04/18/sap-hana-2.0-sps-01-new-developer-features-database-development/

Dynamic SQL:动态 SQL:

EXECUTE IMMEDIATE 'SELECT NEW ST_Point(' || char(39) || 'POINT(' || decEndPointLong1 || ' ' || decEndPointLat1 || ')' || char(39) || ', 4326).ST_Distance( NEW ST_Point(' || char(39) || 'POINT(' || CURRLONG || ' ' || CURRLAT || ')' || char(39) || ', 4326)) FROM DUMMY' INTO dDistEP1;

Then, I thought that I would create a calculation view, This blog says it should work: https://blogs.sap.com/2018/02/23/compute-distance-using-a-calculation-view-xs-advanced-model/然后,我想我会创建一个计算视图,这个博客说它应该可以工作: https : //blogs.sap.com/2018/02/23/compute-distance-using-a-calculation-view-xs-advanced -模型/

But, does not allow the use of spatial functions in ether columnengine or SQL engine.但是,不允许在以太列引擎或 SQL 引擎中使用空间函数。

Calculated Column:计算列:

STPOINT 计算视图

I went back and tried to re-activate the procedure that contains this code and has been working, and still works, but if I edit it and try to activate it has the same compile error.我回去尝试重新激活包含此代码的程序,该程序一直在工作,并且仍然有效,但是如果我编辑它并尝试激活它,则会出现相同的编译错误。 Cannot select into variable.无法选择到变量中。 So, something has changed since I first created this procedure.所以,自从我第一次创建这个程序以来,事情发生了变化。

​Wow, I stumbled upon an alternate syntax that does not need single quotes: ​https://blogs.sap.com/2017/02/17/transforming-spatial-data-in-sap-hana/哇,我偶然发现了一种语法并不需要使用单引号: https://blogs.sap.com/2017/02/17/transforming-spatial-data-in-sap-hana/

SELECT NEW ST_Point(-117.0400842, 32.92197086).ST_SRID(4326).ST_Distance( NEW ST_Point(-117.0394467, 32.92241185).ST_SRID(4326)) FROM DUMMY

Now, I think that I can eliminate the Dynamic SQL.现在,我认为我可以消除动态 SQL。

Looking at the two differ ways:看这两种不同的方式:

1) SELECT NEW ST_Point(-117.0400842, 32.92197086).ST_SRID(4326).ST_Distance( NEW ST_Point(-117.0394467, 32.92241185).ST_SRID(4326)) FROM DUMMY;
2) SELECT NEW ST_Point('POINT(-117.0400842 32.92197086)', 4326).ST_Distance( NEW ST_Point('POINT(-117.0394467 32.92241185)', 4326)) FROM DUMMY;

They yield slightly different results (meters):它们产生略有不同的结果(米):

  1. 77.06 77.06
  2. 77.12 77.12

Probably, because (1) converts a calculated point to 4326, and (2) calculates the point based on 4326.可能是因为(1)将计算的点转换为4326,(2)根据4326计算点。

So, this code:所以,这段代码:

EXECUTE IMMEDIATE 'SELECT NEW ST_Point(' || char(39) || 'POINT(' || decEndPointLong1 || ' ' || decEndPointLat1 || ')' || char(39) || ', 4326).ST_Distance( NEW ST_Point(' || char(39) || 'POINT(' || CURRLONG || ' ' || CURRLAT || ')' || char(39) || ', 4326)) FROM DUMMY' INTO dDistEP1;

​Boiled down to:归结为:

SELECT r1.FROMLAT  INTO decEndPointLat1  FROM DUMMY;
SELECT r1.FROMLONG INTO decEndPointLong1 FROM DUMMY;
SELECT NEW ST_Point(decEndPointLong1, decEndPointLat1).ST_SRID(4326) INTO stEndCoord1 FROM DUMMY;
    
SELECT NEW ST_Point(CURRLONG, CURRLAT).ST_SRID(4326) INTO stCurrCoord FROM DUMMY;
    
SELECT stEndCoord1.ST_Distance(stCurrCoord) INTO dDistEP1 FROM DUMMY;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM