Q&A

  • insert문을 update 문으로...
insert into sm_funtouser_tb                              
      ( user_id, group_code, field_id, authority)          
select a.user_id, c.group_code, c.field_id, c.authority  
from sm_users_tb a, sm_deggroup_tb b, sm_funcgroup_tb c  
where a.user_degree = b.user_degree                    
and b.group_code = c.group_code                          
and c.group_code =  '01'        

위의 insert문을 update문으로 변환하면 어떻게 해야져??
5  COMMENTS
  • Profile
    정말수 2004.01.17 20:15

    Update sm_funtouser_tb Dset
      D.authority = (select c.authority  
                         from sm_users_tb a,
                                sm_deggroup_tb b,
                                sm_funcgroup_tb c  
                         where a.user_degree = b.user_degree                    
                         and b.group_code = c.group_code                          
                         and c.group_code =  '01'  
                         AND D.user_id = a.user_id
                         AND D.group_code = c.group_code
                         AND D.field_id = c.field_id)
    WHERE EXISTS (select *
                            from sm_users_tb a,
                                sm_deggroup_tb b,
                                sm_funcgroup_tb c  
                         where a.user_degree = b.user_degree                    
                         and b.group_code = c.group_code                          
                         and c.group_code =  '01'  
                         AND D.user_id = a.user_id
                         AND D.group_code = c.group_code
                         AND D.field_id = c.field_id)
  • Profile
    곽경래 2004.01.15 03:14
    Update sm_funtouser_tb set
           user_id, group_code, field_id, authority
    select a.user_id, c.group_code, c.field_id, c.authority  
    from sm_users_tb a, sm_deggroup_tb b, sm_funcgroup_tb c  
    where a.user_degree = b.user_degree                    
    and b.group_code = c.group_code                          
    and c.group_code =  '01'  

    이렇게 하면 안될까요....^^;
    그럼 행복하세요....
  • Profile
    연기훈 2004.01.16 02:34
    아 그리고 주의 하실껀

    위같이 코딩하면 group_code 값이 같은 값은 전부 같은 값으로

    변경 된다는 것입니다.

    select 한것에서 키 값을 잘 잡아서 업데이트를 해주세요!
  • Profile
    연기훈 2004.01.16 02:32
    SQL 문 만으로 할려면 불가능 합니다.

    Update 자체 문법이 sub select 를 지원 하지 않으니..

    먼저 select 해오고, 그다음에 update를 해주어야 합니다.

    예)

    qry1.close;
    qry1.SQL.clear;
    qry1.SQL.Test :=   // or qry1.SQL.add
           'select a.user_id       as user_id
                    ,c.group_code as group_code
                    ,c.field_id        as field_id
                    ,c.authority      as authority
               from sm_users_tb a, sm_deggroup_tb b, sm_funcgroup_tb c  
             where a.user_degree = b.user_degree                    
                and b.group_code = c.group_code                          
               and c.group_code =  ''01''  ';
    qry1.open;

    qry2.close;
    qry2.SQL.clear;
    qry2.SQL.text := ' update sm_funtouser_tb set '
                         + ' user_id =  ' + qry1['user_id']
                         + ' field_id = ' + qry1['field+id']
                         + ' authority = ' + qry1['authority']
                         + ' where group_code = ' + qry1['group_code'];
    qry2.exsql //?? 이 명령이 생각이 안나네요.. 머리의 한계



  • Profile
    남궁혁 2004.01.15 03:37

    지금 사용하구 있는 DB는 오라클인데여..
    말씀하신데루 하면..

    아래와 같은 에러가 발생합니다.

    ERROR at line 2:
    ORA-00927: missing equal sign

    도와 주세여~~