检查表中是否存在多条记录ORACLE PLSQL

时间:2016-04-08 18:07:54

标签: oracle plsql exists records

在这里,我想检查记录是否存在,并根据我想要执行的操作。 我的代码如下

     FOR cell_configs IN (SELECT cc.cell_configuration_name,
                                 cc.cell_configuration_value
                            from cell_configurations cc
                            where (cc.cell_configuration_name like height_cc or 
                                    cc.cell_configuration_name like width_cc) and
                                  cc.cell_id=c_id)        
    LOOP
      if cc.cell_configuration_name OR
         cc.cell_configuration_value EXISTS
      then
        -- i want to update the table  dbms_output.put_line(temp || ' does exist');
      else
        -- i want to insert records into the table dbms_output.put_line(temp || ' does not exist');
      end if;

      dbms_output.put_line(c_id || ' ' || 
                           cell_configs.cell_configuration_name || ' ' ||  
                           cell_configs.cell_configuration_value );
    END LOOP;  

如果没有找到记录,我可以看到我会得到空字符串,即''。我无法检查它是否为空。

有人可以帮我这个吗?。

编辑(从评论中复制的信息):

我正在寻找这两行(高度,宽度)cell_configuration_name,如' container.dealer-content.configs [1] .width'或者cell_configuration_name类似于' container.dealer-content.configs [1]。高度' cell_configuration_value = flex-width-8 cell_configuration_value = flex-width-250

下面的CELL_CONFIGURATIONS表

CELL_CONFIGURATION_ID     NUMBER(38,0) PK
CELL_ID                   NUMBER(38,0) FK
CELL_CONFIGURATION_NAME   VARCHAR2(100 BYTE)
CELL_CONFIGURATION_VALUE  VARCHAR2(4000 BYTE)
IS_LOCKED                 CHAR(1 BYTE)
MODIFIED_BY               VARCHAR2(100 BYTE)
MODIFIED_DATE             DATE
CREATED_BY                VARCHAR2(100 BYTE)
CREATED_DATE 

示例数据如下

CELL_ID     CELL_CONFIGURATION_NAME         CELL_CONFIGURATION_VALUE
37771286880 container.dealer-content.configs[1].height  flex-height-2
37771286880 container.dealer-content.configs[1].width   flex-width-8

1 个答案:

答案 0 :(得分:0)

这是解决方案的开始......

BEGIN
  FOR rec IN
  (SELECT cell_id  -- assuming that cell_id will repeat for lines with width and height
  FROM CELL_CONFIGURATIONS
  WHERE CELL_CONFIGURATION_NAME LIKE height_cc
  MINUS
  SELECT cell_id
  FROM CELL_CONFIGURATIONS
  WHERE CELL_CONFIGURATION_NAME LIKE width_cc
  )
  LOOP
     -- INSERT STATEMENT
  END LOOP;
END;