小编Kam*_* K.的帖子

有没有办法在一个脚本中创建多个触发器?

我试图创建多个触发器,只需将一个脚本上传到Oracle DB/APEX工作区,并运行一次.

这是一个简短的脚本,与我试图使用的脚本相比:

    create or replace trigger "BI_TEC_ROLES"   
      before insert on "TEC_ROLES"               
      for each row  
    begin   
      if :NEW."ROLE_ID" is null then 
        select "TEC_ROLES_SEQ".nextval into :NEW."ROLE_ID" from dual; 
      end if; 
    end; 

    create or replace trigger "BI_TEC_STATUSES"   
      before insert on "TEC_STATUSES"               
      for each row  
    begin   
      if :NEW."STATUS_ID" is null then 
        select "TEC_STATUSES_SEQ".nextval into :NEW."STATUS_ID" from dual; 
      end if; 
    end; 

    create or replace trigger "BI_TEC_SUBS"   
      before insert on "TEC_SUBS"               
      for each row  
    begin   
      if :NEW."SUB_ID" is null then 
        select "TEC_SUBS_SEQ".nextval into :NEW."SUB_ID" from …
Run Code Online (Sandbox Code Playgroud)

database oracle triggers plsql

22
推荐指数
2
解决办法
2万
查看次数

将String拆分为String []一段时间但返回一个空数组

好吧,也许我只需要第二双眼睛.

我有一个浮点数,我变成了一个字符串.然后我想用它的周期/小数将它拆分,以便将其作为货币表示.

继承我的代码:

float price = new Float("3.76545");
String itemsPrice = "" + price;
if (itemsPrice.contains(".")){
    String[] breakByDecimal = itemsPrice.split(".");
    System.out.println(itemsPrice + "||" + breakByDecimal.length);
    if (breakByDecimal[1].length() > 2){
        itemsPrice = breakByDecimal[0] + "." + breakByDecimal[1].substring(0, 2);
    } else if (breakByDecimal[1].length() == 1){
        itemsPrice = breakByDecimal[0] + "." + breakByDecimal[1] + "0";                         
    }                           
}
Run Code Online (Sandbox Code Playgroud)

如果你拿这个并运行它,你将在第6行(在上面的代码中)得到一个数组索引越界错误,关于小数后面没有任何内容.

实际上在第5行,当我打印出数组的大小时,它为0.

对于他们而言,这些都是荒谬的错误,而不是我只是忽视的东西.

就像我说的那样,另一双眼睛正是我所需要的,所以在指出一些对你来说很明显的东西时请不要粗鲁,但我忽略了它.

提前致谢!

java arrays string floating-point split

6
推荐指数
1
解决办法
4109
查看次数

无限循环当在try-catch块中捕获InputMidmatchException时

我一直在无限循环中捕获我的代码.

它没什么可提升的,但我无法理解我的生活!

有人请帮忙

我只是重新创建了特定的错误,没有我在实际程序中的所有if语句.

    package bs;

    import java.util.InputMismatchException;
    import java.util.Scanner;

    public class bs {

        public static void main(String[] args) {

            Scanner sc = new Scanner(System.in);

            boolean continueVar = true;

            while (continueVar) {

                try {
                    System.out.println("Enter Something");
                    int input = sc.nextInt();

                } catch (InputMismatchException i) {
                    System.out.println("What the f***?");
                    continueVar = true;
                }
            }


        }
    }
Run Code Online (Sandbox Code Playgroud)

捕获输入不匹配异常时会发生无限循环.我认为它至少会要求用户重新输入他们的输入,但不是这样做,而是继续循环,如下所示:

    run:
    Enter Something
    df
    What the f***?
    Enter Something
    What the f***?
    Enter Something
    What the f***?
Run Code Online (Sandbox Code Playgroud)

它的行为就像只是忽略扫描仪对象sc?!

java exception-handling try-catch infinite-loop java.util.scanner

3
推荐指数
1
解决办法
3106
查看次数