Sql 动态查询结果在Oracle中的应用
下表列出了一些测试数据Sql 动态查询结果在Oracle中的应用,sql,oracle,oracle11g,Sql,Oracle,Oracle11g,下表列出了一些测试数据 create table TestTable ( torque number, torqueValues number ) insert into TestTable values(1,10); insert into TestTable values(1,20); insert into TestTable values(1,30); insert into TestTable values(2,1); insert into TestTable valu
create table TestTable
(
torque number,
torqueValues number
)
insert into TestTable values(1,10);
insert into TestTable values(1,20);
insert into TestTable values(1,30);
insert into TestTable values(2,1);
insert into TestTable values(3,2);
insert into TestTable values(5,10);
insert into TestTable values(9,1);
insert into TestTable values(9,12);
insert into TestTable values(10,15);
insert into TestTable values(10,10);
我试图在oracle中应用NTILE,并将记录集划分为多个组。
当我在下面运行时,它工作正常
select torque,NTILE(2) over(order by torque) from TestTable
但当我试图将动态值传递给NTILE时,它抛出了丢失的表达式错误。下面是查询
select torque,
NTILE(
select count(*)/2 as countvalue from TestTable
over(order by torque) from TestTable
你能指出我哪里出错了吗。同一查询在SQL server上运行良好,但oracle它抛出了错误。
谢谢
同一查询在SQL server上运行良好,但oracle它抛出了错误
否,它也给出了SQL Server中的错误:
在Oracle中使用with
子句尝试此操作,它会起作用
WITH t
AS (
SELECT count(*) / 2 AS countvalue
FROM TestTable
)
SELECT torque
,NTILE(countvalue) OVER (
PARTITION BY countvalue ORDER BY torque
) as tile
FROM TestTable
CROSS JOIN t;
这里需要注意的一点是,需要按countvalue进行分区,否则将抛出此错误
ORA-30488说明:参数应该是表达式的函数
被分割
我仍然无法从Oracle文档或其他任何地方获得上述限制的适当来源。对于SQL Server,即使这样也似乎不起作用:谢谢您的回复。我正在结束这个请求。