Deleting rows from one table while filter condition lies into another table
Hi All,
I'm facing a problem deleting a row from a table where the condition lies in other table. To ealaborate the scenario further let's say I have two table T1 (transaction table) and T2 (Master Table). I want to delete a record from table T1 by checking some conditions lies in table T2.
I tried with the below query but this query deleting records from both the table.
DELETE FROM ( SELECT * FROM T1 top INNER JOIN T2 tp
ON top.TID = tp.TID
WHERE top.DEAL_SITE_ID = inputparameter1
AND (TP.SEGMENT <>inputparameter2 OR tp.segment is not null));
Here the record is getting deleted from both the tables but I don't want to delete data from my master table i.e table T2.
Any help would be highly appreciated. Thanks in advance.
Regards,
Subhadeep
SQL> select *
2 from the_table;
X Y
AA a
BB a
CC a
AA b
DD b
SQL> select *
2 from the_table_2;
X Y
AA a
BB a
CC a
SQL> delete from
2 (
3 select *
4 from the_table t1 inner join the_table_2 t2
5 on t1.x = t2.x
6 and t1.y = t2.y);
3 rows deleted.
SQL> select *
2 from the_table;
X Y
AA b
DD b
SQL> select *
2 from the_table_2;
X Y
AA a
BB a
CC a
Similar Messages
-
Generate xml from a table and insert the xml into another table
I want to generate an xml file from a table and insert it into another table all in one tsql
insert into table B(xmlfile)
select * from tableA
FOR
XML
PATH('ac'),TYPE,ELEMENTS
XSINIL,ROOT('Accum')
Is not working any helpI have solved my issue all I did was to change my column datatype to xml
-
Using a set from one dimension to filter a set on another dimension without using the slicer
I have a complex mdx query. In one step within this I want to restrict the members of one set to those that have data in the cells defined by this first set and a second set on a different dimension. It is not the values in those intersection
cells I want to end up with but just the restricted members of the first set. I am then going to cross join this with the 'All' member of the second set. The point of doing this is that the results can be joined with a union query to other results
with the same dimensionality.
I get what I want, in simplified way, from the following:
with set x as filter([Org].[Dept].[Dept].members,
[Proj].[ProjHierarchy].[Proj].&[100028])
select [Measures].[Finance] on columns, x on rows from projects
This shows the total finance for each dept member that has any finance against the specified project. However, this won't do as what is supplied to the mdx is a string parameter that is converted to a list of members using StrToSet and the MDX above won't
accept this. I do not wish to use the slicer because of the complex overall MDX structure. Is there any way to make something like the above work?Hi Kenneth
does this set have the required dimensionality? :
extract(
nonempty(
( [Org].[Dept].[Dept].members
, [Proj].[ProjHierarchy].[Proj].&[100028])
, [Measures].[Finance])
,[Org].[Dept] )
I'm not sure about the hierachy on the last line. Maybe: [Org].[Dept].[Dept]
Philip, -
How to get the data from one table and insert into another table
Hi,
We have requirement to build OA page with the data needs to be populated from one table and on save data into another table.
For the above requirement what the best way to implement in OAF.
I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
ThanksYou can achieve this in many different ways, one is
1. Create another VO based on the EO which is based on the dest table.
2. At save, copy the contents of the source VO into the dest VO (see copy routine in dev guide).
3. commiting the transaction will push the data into the dest table on which the dest VO is based.
I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
if by table you mean a DB table, then no, you can have a VO based on multiple EOs which will do DMLs accordingly.Thanks
Tapash -
Deleting rows from very large table
Hello,
I need to delete rows from a large table, but not all of them, so I can't use truncate. The delete condition is based on one column, something like this:
delete from very_large_table where col1=100;
There's an index (valid, B-tree) on col1, but it still goes very slow. Is there any instruction which can help delete rows faster?
Txh in adv.
A.Your manager doesn't agree to your running an EXPLAIN PLAN? What is his objection? Sounds like the prototypical 'pointy-hair boss'.
Take a look at these:
-- do_explain.sql
spool explain.txt
-- do EXPLAIN PLAN on target queries with current index definitions
truncate table plan_table
set echo on
explain plan for
<insert query here>
set echo off
@get_explain.sql
-- get_explain.sql
set linesize 120
set pagesize 70
column operation format a25
column query_plan format a35
column options format a15
column object_name format a20
column order format a12
column opt format a6
select lpad(' ',level) || operation "OPERATION",
options "OPTIONS",
decode(to_char(id),'0','COST = ' || NVL(to_char(position),'n/a'),object_name) "OBJECT NAME",
cardinality "rows",
substr(optimizer,1,6) "OPT"
from plan_table
start with id = 0
connect by prior id = parent_id
There are probably newer, better ways, but this should work with all living versions of Oracle and is something I've had in my back pocket for several years now. It's not actually executing the query or dml in question, just running an explain plan on it. -
Oracle deleting rows from tables starting with the name PQ
hai friends
we are given access rights to delete only tables starting with PQ. HAVING PQ_NUM as primary key for all the PQ tables.
totally we have 6 tables. PQ_01,PQ_02, PQ_03,PQ_04,PQ_05,PQ_06.
ALL This tables will have one primary key. for example pq_01 willl have pq01_num as primarykey and pq_02 table will have pq02_num as primary
key.
pq01_num value will exist in all the primary key of pq tables.
i want query to delete rows from the pq tables based on the input value i give.
for example if i give primarykey value 122 then that value in pq tables should be deleted.
One more problem is there. pq_06 table does not have pq02_num column. here the column differs. it is pq06_num_req.
so give your idea of deleting the rows from pq tables
waiting
SI dont have access to databse,this is untested
declare
v_cmd varchar2(2000);
columnname varchar2(30);
input_value number:=??;
tabowner varchar2(30):=???
begin
--step 1 identify table
FOR sub IN (SELECT table_name table_to_delete
FROM all_tables
WHERE table_name LIKE 'PQ%'
and owner=tabowner
) LOOP
----step 2 identify column
v_cmd :='select t.column_name from all_constraints S,All_Ind_Columns T where
S.OWNER=T.TABLE_OWNER
AND S.TABLE_NAME=T.TABLE_NAME
AND S.INDEX_NAME=T.INDEX_NAME
and s.owner=tabowner
AND S.TABLE_NAME='||table_to_delete||'
and s.constraint_type='''P'';
execute immediate v_cmd into columnname;
--step 3 delete records
v_cmd := 'delete from '||tabowner||'.' ||
sub.table_to_delete || '
where '||columnname||'='||input_value;
execute immediate v_cmd;
commit;
END LOOP;
end;Edited by: user5495111 on Aug 11, 2009 6:35 AM -
Delete rows from table...Bizarre problem.
Folks
i HAVE this bizarre problem.
I hava a Java class which displays data read into a table with a delete
option by the side of each row.
Now lets assume you have 3 rows in the Table.
abc deleteButton
efg deleteButton
xyz deleteButton
When I click the first delete,that row gets deleted from the table.(perfect...)
Now I have 2 rows.
When I click on the first row,I get the error
'You clicked -1'
java.lang.ArrayIndexOutofBoundsException: -1 < 0.
Can anyone tell me why this is happening even though there are rows in the table.???
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("You clicked row : " + table.getSelectedRow());
javax.swing.table.TableModel model = table.getModel();
Object o = model.getValueAt(table.getSelectedRow(),0);
//System.out.print(model.getValueAt(table.getSelectedRow(), 0));
//System.out.println();
MyDeleteFunction(o.toString());
// Delete row from window.
((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow());
table.revalidate();
table.repaint();Hi ritu,
This class is called
new DisplayCall_IDTodisconnect(hashTable);
its a long file.
its attached below.
The rows are displayed by reading a hashtable into a vector
and the vector is iterated and appended..
public class DisplayCall_IDToDisconnect {
public static JTable createTable(Vector data, String buttonLabel, ActionListener action){
return createTable(data.iterator(), buttonLabel, action);
public static JTable createTable(
Iterator dataIterator,
String buttonLabel,
ActionListener action) {
DefaultTableModel model = new DefaultTableModel() {
public boolean isCellEditable(int row, int col) {
return col == 1;
model.setColumnCount(2);
while (dataIterator.hasNext()) {
Object[] row = { dataIterator.next().toString(), null };
model.addRow(row);
DefaultTableColumnModel columnModel = new DefaultTableColumnModel();
columnModel.addColumn(new TableColumn(0, 100));
columnModel.addColumn(new TableColumn(1, 80,
new TableButtonCellRenderer(buttonLabel),
new TableButtonCellEditor(buttonLabel, action)
JTable table = new JTable(model, columnModel) {
public void valueChanged(ListSelectionEvent e) {
super.valueChanged(e);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
return table;
private static class TableButtonCellRenderer implements TableCellRenderer {
final JButton button;
TableButtonCellRenderer(String buttonLabel) {
button = new JButton(buttonLabel);
public Component getTableCellRendererComponent(
JTable table,
Object value,
boolean isSelected,
boolean hasFocus, int row, int column) {
return button;
private static class TableButtonCellEditor
extends AbstractCellEditor
implements TableCellEditor, ActionListener {
final JButton button;
final ActionListener callback;
TableButtonCellEditor(String buttonLabel, ActionListener callback) {
button = new JButton(buttonLabel);
this.callback = callback;
button.addActionListener(this);
public Component getTableCellEditorComponent(
JTable table,
Object value,
boolean isSelected,
int row, int column) {
return button;
public Object getCellEditorValue() {
return null;
public void actionPerformed(ActionEvent e) {
button.getParent().requestFocus();
callback.actionPerformed(e);
static JTable table;
Vector items;
final ClientManager clientMgr;
// Constructor.
public DisplayCall_IDToDisconnect(Hashtable callLegTable,ClientManager clientMgr){
Vector vCSeqnos = displayCSeqNos(callLegTable);
this.clientMgr = clientMgr;
JFrame frame = new JFrame("Disconnect Options");
/*Vector*/ items = new Vector();
Enumeration vEnum = vCSeqnos.elements();
while(vEnum.hasMoreElements()){
items.add(vEnum.nextElement());
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent e) {
//System.out.println("You clicked row ,col: " + table.getSelectedRow()+
// table.getSelectedColumn());
javax.swing.table.TableModel model = table.getModel();
Object o = model.getValueAt(table.getSelectedRow(),0);
System.out.print(model.getValueAt(table.getSelectedRow(), 0));
System.out.println();
closeConnection(o.toString());
// Delete row from window too.
((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow());
table.revalidate();
table = DisplayCSeqNos.createTable(items, "Disconnect", al);
frame.getContentPane().add(new JScrollPane(table));
frame.pack();
frame.show();
} // End Constructor.
public void closeConnection(String s){
/*1. Disconnect the current session*/
this.clientMgr.disconnectCall(s);
/*2. refresh the Disconnect window*/
this.refreshWindow();
public Vector displayCSeqNos(Hashtable callLegTable){
Enumeration eNum;
String str;
Vector v = new Vector();
eNum=callLegTable.keys();
while(eNum.hasMoreElements()){
str = (String) eNum.nextElement();
//System.out.println("Key : " + str + " Value : " + callLegTable.get(str));
v.addElement(str);
return v;
} // End of displayCSeqNos. -
Prevent user from deleting rows from all tables in his own schema
Hi,
How can I prevent user from deleting rows in all tables in his own schema.
I want the user to not able to delete rows from any existing or new tables that might be added in the future.
The user does not have the "DELETE ANY TABLE" system privilege.
Please advise.
Thanks.Nowadays, I'd also avoid triggers (if possible).
Sometimes, when I daydream, I'm rewriting a few applications that I've contributed to as a newbie, and I'm very ashamed of it nowadays.
From what I've experienced, in retrospective, the emphasis on teaching 'Oracle stuff' has been lying far too much on PL/SQL row-by-row oriented processing instead of letting Oracle 'crunch' sets at once.
Most of my debugging hours ended up in discovering one or more database triggers 'doing stuff automagically'.
Another nice blogpost: http://rwijk.blogspot.com/2007/09/database-triggers-are-evil.html
Regarding OP's question:
I would just rethink/reconsider this requirement completely.
Correctly implementing privileges and roles seems the best way to go, yes.
Triggers? Nah...
pre-post-edit, noticed thread got updated just before posting
Don't know what you mean with 'namedropping', but I think it's legitimate to point other readers to interesting Oracle related opinions/articles that do have a technical background and lots of interesting examples.
post dreaded OTN outage edit (from here)
Again: I would just rethink/reconsider this requirement completely.
Both trigger/vpd are being used to hide a design flaw here. -
COuld anyone tell me how to delete rows from a table which has millions of rows.
TIA,
Oracle userif you are deleting all the rows, use "truncate table" in sql*plus.
or if you are deleting all but a handful of rows, then copy the rows you still want to a spare table, drop the original table, and rename the spare table back to the original table's name.
hope this helps -
Copying table rows from one table to another table form
Hi
I have a problem about Copying table rows from one table to another table form.On jsf pages if you enter command button go anather jsf page and it copy one row to another table row. But when i execute this process for table FORM it doesn't copy I wrote a code under "createRowFromResultSet - overridden for custom java data source support." Code block is:
ViewRowImpl value = super.createRowFromResultSet(qc, resultSet);
try{
AdfFacesContext fct = AdfFacesContext.getCurrentInstance();
Number abc = (Number)fct.getProcessScope().get("___");
value.setAttribute("___",abc);
}catch(Exception ex){System.out.println(ex); }
return value;Table may be copied with the
expdp and impdp utilities.
http://www.oracle.com/technology/products/database/utilities/index.html -
Passing Multiple table row from one view to another view
Hi,
How to Passing Multiple table row from one view to another view in Web Dynpro Abap. (Table UI Element)
thanx....Hi Ganesh,
Kindly do search before posting.. this discussed many times..
First create your context in component controller, and do context mapping in two views so that you can get values from
one veiw to any views.
and for multiple selection, for table we have property selection mode.. set as multi and remember context node selection
selection cardinality shoud be 0-n.
so, select n no of rows and based on some action call sec view and display data.( i think you know navigation between veiw ).
Pelase check this...for multi selection
Re: How to copy data from one node to another or fromone table to another table
for navigation.. check
navigation between the views
Cheers,
Kris. -
Web Dynpro ALV table contents from context comes without filter conditions
Hi Experts,
Please help me to solve this problem.
I set some selfmade functions on tool bar of my WD ALV,
and it works OK, but when I set some filter conditions,
I get same table contents in my method ONFUNCTION.
What can I do?
Thank you very much
IrenaMy question was about option Filter of ALV report.
May be somebody knows how I can receive Interfacecontroller
attributes: FILTER_VALUES. It should help to filter
table inside code( in my ONFUNCTION method).
Regards
Irena -
Unable to delete rows from Target.
Hello everyone,
I am unable to delete rows from target data store. Here is what I have done.
Source Oracle 10g - staging 11g - Target Oracle 11g
I have implemented consistent set CDC on data model in staging and added 2 tables to CDC and turned on the journals . Both tables A and B are joined together via Column E (primary key of table A). Table A is the master table(has foreign key). Table B is child table. Target column consists of all the columns of both table A and B.
Following is what I am able to do and not to do
ABLE TO DO. If data is inserted into both or any of journalized tables I can successfully load the same in target by performing following steps. 1. Extend the consistency window at model level. Lock subscriber. Run the interface with any source table marked as Journalized data only. Unlock subscriber and purge journal.
ABLE TO DO. If data is updated in any of the journalized table, along with the steps mentioned above I can execute two interfaces. In one Interface table A marked as journalized data only Joined with table B and in second interface table B marked as Journalized data only joined to table a.
NOT ABLE TO DO If data is deleted from one or both tables it shows up as journalized data in JV$D<tablename> marked as D with date and subscriber name but when i run the interface by extending the window , locking subscriber executing both interfaces, unlock subscriber purge journals. no change takes place is Target. After unlocking subscriber step, journalized data gets removed from JV$D view. Please let me know what I am doing wrong here. How can rows delted from source can also be deleted from TARGET?
NOTE : In the flow table SYNC_JRNL_DELETES is YES
In moel under jounalized table tab Table have following order Table A folloed by Table B
Thanks in advance
GreenwichSorry I still do not get it. when you say "Its a legacy app", are you talking about the VB.NET app ?
If so then I repeat my self :-) Why not to connecting to the SQL server directly?
* even if you need information from several databases (for example ACCESS + SQL Server), in most cases, it is much better to connect directly and get each information to the app. Then in your app you can combine the information and analyse it
[Personal Site] [Blog] [Facebook]
Access app is the legacy app. -
Add/Delete rows from ALV-grid
Hi to all,
i have 2 questions concerning alv-grids:
i have an alvgrid displaying a table and what i need is some functionality to add or delete rows from the alvgrid - how can i do that ?
within one row i have one field containing the status and i want to be able to select the status from a combo/dropdown-field and set it for this particular row.
thanks in advance!Hi,
Report BCALV_EDIT_04 shows how to append and delete rows.
Report BCALV_EDIT_06 shows drop down list for cells in a column.
These report should be available in any R/3 system including all ABAP Preview versions.
Hope this can help.
Regards, Johan -
Delete Rows from T1 which are Not in T2
Hi
I've 2 Tables like below
T1
N1
N2
2
11
2
22
3
33
8
44
8
88
T2
N1
N2
2
22
8
88
If I Run Delete query, I must delete Rows from T1 which are Not in T2
For example, I must delete Rows 1,3,4 from T1
So how to write that delete query? Please adviceDelete from T1
Where not Exists (select * from T2 Where t1.N1=t2.N1 and t1.N2=t2.N2)
--or
Delete t
From t1 t
left JOIN t2 m
ON m.N1=t.N1 and m.N2=t.N2
WHERE m.N1 is null and m.N2 is null
--Or
;With mycte as
select N1,N2 from T1
Except
select N1,N2 from T2
Delete t
From t1 t
INNER JOIN mycte m
ON m.N1=t.N1 and m.N2=t.N2
Maybe you are looking for
-
Copy from thumb drive to macbook pro
How to copy from thumb drive to macbook pro. Pictures
-
Getting img tags to work in sub page using jstl core import tag
Am trying to bring disparate system page reports together under one web app. This means using the jstl core import tag (I dont want to redirect as I want to hide the urls, this web app provides better security than those it calls). Use of the import
-
How to call the abap program in workflow
HI Exeprts, I need to call one abap program in workflow. can any tell me how to call the abap program in workflow. thanks ®ards ramesh
-
Adobe Acrobat X Pro Update Error 2379
Each time I attempt to update Adobe Acrobat X Pro I am greeted with the following error message: Error 2379.Error Opening file for read: C:\Program Files (x86)\Adobe\Acrobat 10.0\Acrobat\Acrobat.exe GetLastError:5. Any idea on how to resolve this is
-
Installed New DVD burner, but it will not burn DVDs
I just installed a new Pioneer DVR-112D DVD burner but when I try to burn a DVD with iDVD 4 it will not burn a DVD. It looks like iDVD 4 will get to stage 4 of the process but it will not finish burning the DVD. Can anyone help me out? Thank you Nels