sql - Populating table B with data from table A if data in table B is different to table A -
apolgies confusing heading , long winded post.
i attempting populate (oracle) sql table data can monitor on regular basis , build picture of users use application modules.
i have table 'forms_sessions_log' created follows:
create table stuman.forms_sessions_log ( select a.sid, a.serial#, a.logon_time, a.client_identifier, a.module,a.username, a.schemaname, b.spriden_last_name, b.spriden_first_name gv$session a, spriden b program 'frmweb%' , a.username=b.spriden_id)
this creates 'snapshot' of 'forms' sessions connected database @ point in time.
from on, each minute via job scheduler, i'd continue populate table new or different sessions.
i came following:
insert stuman.forms_sessions_log (sid,serial#,logon_time,client_identifier,module,username,schemaname,spriden_last_name,spriden_first_name) select a.sid, a.serial#, a.logon_time, a.client_identifier, a.module , a.username, a.schemaname, b.spriden_last_name, b.spriden_first_name gv$session spriden b a.program 'frmweb%' , a.username=b.spriden_id , not exists(select * stuman.forms_sessions_log) /
this didn't seem work. failed add new sessions. if truncate stuman.forms_sessions_log , run insert statement again, populates fine fails add new sessions table on consecutive attempts.
i looked @ code , decided fine tune statement using comparisons in not exists clause.
insert stuman.forms_sessions_log (sid,serial#,logon_time,client_identifier,module,username,schemaname,spriden_last_name,spriden_first_name) select a.sid, a.serial#, a.logon_time, a.client_identifier, a.module , a.username, a.schemaname, b.spriden_last_name, b.spriden_first_name gv$session a, spriden b a.program 'frmweb%' , a.username=b.spriden_id , not exists(select a.sid,a.serial#,a.logon_time,a.client_identifier,a.module,a.username,a.schemaname stuman.forms_sessions_log a, gv$session b a.sid=b.sid , a.serial#=b.serial# , a.logon_time=b.logon_time , a.client_identifier=b.client_identifier , a.module=b.module , a.username=b.username , a.schemaname=b.schemaname ) /
this doesn't expecting. isolated not exists part of query wanted check is:
select a.sid,a.serial#,a.logon_time,a.client_identifier,a.module,a.username,a.schemaname stuman.forms_sessions_log a, gv$session b a.sid=b.sid , a.serial#=b.serial# , a.logon_time=b.logon_time , a.client_identifier=b.client_identifier , a.module=b.module , a.username=b.username , a.schemaname=b.schemaname
now, bear in mind defined fields in both table , b identical (stuman.forms_session_log populated gv$session), nothing returns.
i have 1 row stuman.forms_session_log corresponds row in gv$session.
why select statement above not returning results?
have tried user merge?
merge stuman.forms_sessions_log sl using (select a.sid, a.serial#, a.logon_time, a.client_identifier, a.module , a.username, a.schemaname, b.spriden_last_name, b.spriden_first_name gv$session a, spriden b a.program 'frmweb%' , a.username=b.spriden_id ) s on ( s.sid = sl.sid , s.serial# = sl.serial#) when not matched insert (sid,serial#,logon_time,client_identifier,module,username,schemaname,spriden_last_name,spriden_first_name) values (s.*)
Comments
Post a Comment