添加后缀以重复记录 [英] Add the suffix for repeated records

查看:62
本文介绍了添加后缀以重复记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做的项目中存储了相同的名称记录,所以我想为所有记录添加后缀,例如Comp1,Comp2 ... Comp10.

i''m doing the project in that store the same name records,so i want to add the suffix for all record as like Comp1,Comp2...Comp10.

推荐答案

创建过程以在数据库中插入数据.使用适当的参数从代码中调用proc.


create procedure to insert data in database., call the proc from your code with appropriete params.


create proc myInsertProc
Begin
  
  //first get the matching records, with the query ilke
  
  select count(1) into variable1 from table1 where column1 like 'Comp%';

   if variable1 > 0
      variable2 = 'Comp' + variable1;
   else  
      variable2 = 'Comp';
   end if;
   
   insert into table1 (column1) values (variable2);
End


我也同意Mehdi Gholam的观点,这个问题非常普遍,您可以将每个记录转换为常量)添加到字符串并为其添加一个计数器(循环中)以生成其!


我编写了此递归函数,可以将其用于生成:
I also agree with Mehdi Gholam, this problem is very ordinary, you can convert each record (in constant) to string and adding it a counter (in loop) for generate its!


I wrote this recursive function and you can use it for generate:
string f(string ConstStr, int from, int to)
{
    if (to == from)
        return ConstStr + from + ",";
    else
        return f(ConstStr, from, to - 1) + ConstStr + to + ",";
}



最后,您可以使用,"来修饰句子,如下所示:



Finally, you can pharse the sentence with "," like this:

string str = f("Mehdi", 1, 5);
string[] strArr = str.Split(new char[] { ',' });


这篇关于添加后缀以重复记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆