如何根据列名创建自动增量表?
标题可能有点令人困惑,但我会尝试在这里更好地解释。
我要实现的是:
创建一个带有3列的表(到目前为止很好):
创建表statisticcounter (( 始终生成的统计数字始终为身份(以1000的增量启动1), Statistikname varchar(255), 计数器整数 );
创建一种调用方法(函数,过程,触发器或其他内容。我现在将其称为函数),将其称为
Counter
1基于statistikname
或StatisticId
。
这里的限制是:所述统计量是一个SQL脚本,该脚本通过座舱文件传播,其语法与常规SQL不同(in:out:of:select,with with with variables)。我想在此座舱文件中放置一个函数或某些内容,每次运行脚本时都会运行。它将自动增加使用统计量的次数。
我不知道我需要什么(功能,过程,触发器或其他任何内容),这就是为什么我写一些含糊的原因。
编辑:我尝试使用合并,但我总是得到不匹配的结果执行。没有施放它。
merge into StatisticCounter stc using
CAST((select 1000 id from dual)AS INTEGER) val on (stc.statisticid=val.id)
when matched then
UPDATE StatisticCounter SET counter = counter + 1;
when not matched then
select * from dual;
The title might be a little confusing but I will try explaining here better.
What I want to achieve is:
Create a table with 3 columns (so far so good):
CREATE TABLE StatisticCounter ( statisticID NUMBER GENERATED ALWAYS as IDENTITY (START with 1000 INCREMENT by 1), statistikname varchar(255), counter integer );
Create a way to call (function, procedure, trigger or something. I will call it function for now) that will increment
counter
with 1 based onstatistikname
orstatisticid
.
The restriction here being: said statistic is an SQL script ran through a cockpit file with a little bit of a different syntax than regular sql (in: out: select, WHERE with variables). I want to put a function or something in this cockpit file, that will run each time the script is run. Which will auto increment the number of times the statistic has been used.
I have no idea what I need (function, procedure, trigger or anything else) and this is why I am writing it a bit vague.
EDIT: I tried with merge but I always get the WHEN NOT MATCHED result executed. Without CAST its the same.
merge into StatisticCounter stc using
CAST((select 1000 id from dual)AS INTEGER) val on (stc.statisticid=val.id)
when matched then
UPDATE StatisticCounter SET counter = counter + 1;
when not matched then
select * from dual;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过许多功能和过程后,我自己找到了答案。
这里重要的是,执行SQL的外部_cockpit文件会贯穿每行的所有OUT参数,结果统计返回。这使柜台变得疯狂 - 无法抓住统计范围或开始。因此,我做了第二个_cockpit,只有1个结果,然后将其附加到我要计算的统计数据上。
I found an answer on my own after going through a lot of functions and procedures.
The important thing here is that the outside _cockpit file that executes the SQL goes through all OUT parameters for each line the statistic returns as result. This makes the counter go wild - no way to catch END of statistic or beginning. So I made a second _cockpit with only 1 result and attach it to the statistic I want to count.