Oracle函数向SQL Server的转换

时间:2018-11-13 01:46:27

标签: sql sql-server oracle tsql stored-functions

我简化了下面的一个案例,它是Oracle中的一个函数。出于某种原因,我需要在SQL Server数据库上进行测试,但由于对SQL Server的了解不多,我迷路了。虽然我知道我需要证明自己的尝试方式,但我对SQL的转换是如此可悲,几乎每个字符都被标记为错误并显示为红色!

有人可以给我提示如何执行此操作。基本上是使用两个表创建一个逗号分隔的列表。如此简单,却如此令人沮丧!请轻柔...这是我的第一篇SQL帖子:-)

CREATE or REPLACE FUNCTION ListOfOrdersFunction
(inputKey IN NUMBER)
RETURN VARCHAR2 IS orderNumbers VARCHAR2(3000);

BEGIN
  SELECT DISTINCT
    LISTAGG (selection.order_number, ',') WITHIN GROUP (ORDER BY selection.customer_id)
    OVER(PARTITION BY selection.customer_id)
    INTO orderNumbers
    FROM (
      SELECT 
      customers.customerId AS customer_id
      ,orders.orderNumber AS order_number
      FROM customberTable customers
           LEFT JOIN ordersTable orders ON orders.order_key = customers.order_key
           WHERE 
                customers.customerId = inputKey
    ) selection;
  RETURN orderNumbers
END;

0 个答案:

没有答案