Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
oraclesql中的Replace函数_Sql_Oracle_Replace - Fatal编程技术网

oraclesql中的Replace函数

oraclesql中的Replace函数,sql,oracle,replace,Sql,Oracle,Replace,我正在使用oracle SQL,我有以下查询: select replace(replace('count(distinct <thiscol>) over (partition by <nextcol>) / count(*) over () as <thiscol>_<nextcol>,', '<thiscol>', column_name )

我正在使用oracle SQL,我有以下查询:

select replace(replace('count(distinct <thiscol>) over (partition by <nextcol>) / count(*) over () as <thiscol>_<nextcol>,',
                       '<thiscol>', column_name
                      ), '<nextcol>', lead(column_name) over (order by column_id)
              )
from all_tab_columns atc
where table_name = 'mytable'
我希望得到的不是:

count(distinct name2) over (partition by name3) / count(*) over ()
此查询:

count(distinct name3) over (partition by name2) / count(*) over ()
任何人都可以建议如何替换列值的顺序?(
)。我试图用
替换
,但它给了我同样的结果。我尝试了许多其他的事情,取得了成功

有人吗?

真奇怪。相反,让我们按相反的顺序排序:

select replace(replace('count(distinct <thiscol>) over (partition by <nextcol>) / count(*) over () as <thiscol>_<nextcol>,',
                       '<thiscol>', column_name
                      ), '<nextcol>', lead(column_name) over (order by column_id desc)
              )
from all_tab_columns atc
where table_name = 'mytable';
选择replace(replace('count(distinct)over(partition by)/count(*)over()as quot,
'',列名称
),'',领先(列名称)超过(按列id描述排序)
)
从所有选项卡栏atc
其中table_name='mytable';

注意排序中的
desc

您得到了什么输出,以及它与您想要的有什么不同?另外,请用人类语言(而不是SQL)对您试图实现的目标进行解释。完成。希望足够清楚。然后可能需要使用
LAG
而不是
LEAD
?只有over()中的值已更改。另一个没有。@GordonLinoff.你太棒了!非常感谢你!我从你身上学到了很多。非常感谢!
select replace(replace('count(distinct <thiscol>) over (partition by <nextcol>) / count(*) over () as <thiscol>_<nextcol>,',
                       '<thiscol>', column_name
                      ), '<nextcol>', lead(column_name) over (order by column_id desc)
              )
from all_tab_columns atc
where table_name = 'mytable';