How to find records given a child parent key
I have a main table that is parent for several children tables. I want to display a button to delete a record in the primary table. I would have preferred to see the this key conditionally so when a master record's child records, I don't show button Delete and no error is raised.Of course I could scan each child table to find the child records, but I think that must be a generic method
How can I tell if a given parent key has child records?
Thanks in advance
Oscar
PS: I use 10 gr 2
Published by: user10712087 on 01/13/2009 14:31
Oscar
There is no magic/generic way to verify that a main line has no associated detail line. As says Pavan, you must decide which detail the tables to check and them using SQL as usual. (In fact, there is a quick way - you remove the line if there is no child rows with foreign keys which is not cascade, the delete will fail; but of course you can't use this in case the deletion succeeds and the user never wants to push the button).
An addition to the Pavan response: DO NOT under any circumstances to count all records in the table of every detail. Everything you want to know is, is it at least 1 record retail at least 1 tables. No need to count the lines 100 or 1000...
You can do it like this in your PL/SQL
FUNCTION check_children(p_master_id IN INTEGER) RETURN BOOLEAN
IS
CURSOR c_child1 IS
select 1 from child_table_1 where master_id = check_children.p_master_id;
CURSOR c_child2 IS
select 1 from child_table_2 where master_id = check_children.p_master_id;
-- etc for all child tables
l_rec_present integer := null;
BEGIN
OPEN c_child_1;
FETCH c_child_1 INTO l_rec_present;
CLOSE c_child_1;
IF l_rec_present i= 1 THEN
-- there is a child in child_table_1
RETURN TRUE;
END IF;
OPEN c_child_2;
FETCH c_child_2 INTO l_rec_present;
CLOSE c_child_2;
IF l_rec_present i= 1 THEN
RETURN TRUE;
END IF;
-- etc for each child; finally, if no child found:
RETURN FALSE;
END;
This made sure that (1) you stop once you find any child, and (2) you get all NO_DATA_FOUND and TOO_MANY_ROWS exceptions thrown.
HTH
Nigel cordially
Tags: Database
Similar Questions
-
How to find passwords for my child?
Related to: Family Safety: fair to the
I like the administrator would like to find password of my child
You don't see it, but you can change the password to something else, or even to delete the password completely.
- Press Windows + R to display the run, type NETPLWIZ and click OK.
- In the box that opens, select the user, then click on "change password".
-
How to find records of value for a specific period of time?
Hello
I'm building an application where I need to use BDB to store tons of documents of the call.
In the files, I have the following fields:
1. appellant's
2. to the appellant
3. start time
4. end of time
5. account code
6. user code
I want to use the representation of microsecond of end times to use the key.
So, how can I do the following database search?
1. research all records of value between 2009-10-11, and now()
2. find the value of all records between 2009-10-11 to now() with account-code = 100
3. find the value of all records between 2009-10-11 to now() with account-code = 100 and user code = 10
Are there similar examples out there that I can do?
Thank you
JBLook at this:
http://www.Oracle.com/technology/documentation/Berkeley-DB/DB/api_c/dbc_get.html#DB_SET_RANGE -
System recovery - how to find records
I recently did a system recovery. I saved my files on a USB I have updloaded to my computer. Download created an icon on my desktop I can access; However, I can't locate the files of type of user such as pictures, word documents or excel spreadsheets. Any help? Thanks in advance.
Sorry, what that tells me is that you have created a recovery discs to restore your computer to the original factory Conditions.
Your personal files are gone unless you have saved the separately using a third-party backup program.
System Restore also means that you will have to reinstall all your programs such as Word, Excel and everything you had installed.
-
I have the following:
2.6
2.6.1
2.6.1.1
2.6.1.2
2.6.2
I want to:
2.6.1.1
2.6.1.2
2.6.2
Please give me some advice, thank you!And if you do not want regular expressions, you can use the normal string functions...
SQL> ed Wrote file afiedt.buf 1 with s as (SELECT '2.6' num FROM dual UNION ALL 2 SELECT '2.6.1' num FROM dual UNION ALL 3 SELECT '2.6.1.1' num FROM dual UNION ALL 4 SELECT '2.6.1.2' num FROM dual UNION ALL 5 SELECT '2.6.2' num FROM dual) 6 -- 7 select num 8 from s 9 where connect_by_isleaf = 1 10 connect by substr(num,1,instr(num,'.',-1)-1) = prior num 11* start with num = '2.6' SQL> / NUM -------------------- 2.6.1.1 2.6.1.2 2.6.2 SQL>
-
Where and how to find the wep or wpa security key?
I am trying to go to Xbox 360 live. I bought a direct card and it worked fine after that I entered the subscription on the map code. The next day, I was unable to sign. I have tried everything I know, but now he wants my wep or wpa security key. I didn't when I first adding them. I am usuing a wi - fi connection and cannot locate a wep or wpa security key. Can you possibly tell me where to find it?
Hello
The WEP or WPA security key is stored on the page of the router. I suggest you to connect on the router's Web page and retrieve the key that could help connect the Xbox.
If the above mentioned steps article does not help, then it would be better to post the same question in the Xbox forum to get help. We have a dedicated team to help you with such questions.
Forum Xbox: http://forums.Xbox.com/?XR=shellnav
Hope the information is useful.
-
How to find the owner of the Windows Server 2003 product key?
I found the Windows 2003 product key on my server, I don't know since I'm new to the company the product key is authentic and I have no record. How to find the owner of the product key?
You find the original product cost and then you are the owner (the company is).
If not - you have not. There is no need to register, activate. When it is activated...
-
How to find the child level for each table in a relational model?
Earthlings,
I need your help, and I know that, "Yes, we can change." Change this thread to a question answered.
So: How to find the child level for each table in a relational model?
I have a database of relacional (9.2), all right?
Tips:. O /* This is a child who makes N references to each of the follow N parent tables (here: three), and so on. */ /↑\ Fks O"O O" <-- level 2 for first table (circle) /↑\ Fks "o"o"o" <-- level 1 for middle table (circle) ↑ Fk "º"
-Each circle represents a table;
-Red no tables have foreign key
-the picture on the front line of tree, for example, a level 3, but when 3 becomes N? How is N? That is the question.
I started to think about the following:
First of all, I need to know how to take the kids:
Thought...select distinct child.table_name child from all_cons_columns father join all_cons_columns child using (owner, position) join (select child.owner, child.constraint_name fk, child.table_name child, child.r_constraint_name pk, father.table_name father from all_constraints father, all_constraints child where child.r_owner = father.owner and child.r_constraint_name = father.constraint_name and father.constraint_type in ('P', 'U') and child.constraint_type = 'R' and child.owner = 'OWNER') aux using (owner) where child.constraint_name = aux.fk and child.table_name = aux.child and father.constraint_name = aux.pk and father.table_name = aux.father;
We will share!
Thanks in advance,
Philips
Published by: BluShadow on April 1st, 2011 15:08
formatting of code and hierarchy for readbilityHave you looked to see if there is a cycle in the graph of dependence? Is there a table that has a foreign key to B and B has a back of A foreign key?
SQL> create table my_emp ( 2 emp_id number primary key, 3 emp_name varchar2(10), 4 manager_id number 5 ); Table created. SQL> ed Wrote file afiedt.buf 1 create table my_mgr ( 2 manager_id number primary key, 3 employee_id number references my_emp( emp_id ), 4 purchasing_authority number 5* ) SQL> / Table created. SQL> alter table my_emp 2 add constraint fk_emp_mgr foreign key( manager_id ) 3 references my_mgr( manager_id ); Table altered. SQL> ed Wrote file afiedt.buf 1 select level lvl, 2 child_table_name, 3 sys_connect_by_path( child_table_name, '/' ) path 4 from (select parent.table_name parent_table_name, 5 parent.constraint_name parent_constraint_name, 6 child.table_name child_table_name, 7 child.constraint_name child_constraint_name 8 from user_constraints parent, 9 user_constraints child 10 where child.constraint_type = 'R' 11 and parent.constraint_type = 'P' 12 and child.r_constraint_name = parent.constraint_name 13 union all 14 select null, 15 null, 16 table_name, 17 constraint_name 18 from user_constraints 19 where constraint_type = 'P') 20 start with child_table_name = 'MY_EMP' 21* connect by prior child_table_name = parent_table_name SQL> / ERROR: ORA-01436: CONNECT BY loop in user data
If you have a cycle, you have some problems.
(1) it is a NOCYCLE keyword does not cause the error, but that probably requires an Oracle version which is not so far off support. I don't think it was available at the time 9.2 but I don't have anything old enough to test on
SQL> ed Wrote file afiedt.buf 1 select level lvl, 2 child_table_name, 3 sys_connect_by_path( child_table_name, '/' ) path 4 from (select parent.table_name parent_table_name, 5 parent.constraint_name parent_constraint_name, 6 child.table_name child_table_name, 7 child.constraint_name child_constraint_name 8 from user_constraints parent, 9 user_constraints child 10 where child.constraint_type = 'R' 11 and parent.constraint_type = 'P' 12 and child.r_constraint_name = parent.constraint_name 13 union all 14 select null, 15 null, 16 table_name, 17 constraint_name 18 from user_constraints 19 where constraint_type = 'P') 20 start with child_table_name = 'MY_EMP' 21* connect by nocycle prior child_table_name = parent_table_name SQL> / LVL CHILD_TABLE_NAME PATH ---------- ------------------------------ -------------------- 1 MY_EMP /MY_EMP 2 MY_MGR /MY_EMP/MY_MGR 1 MY_EMP /MY_EMP 2 MY_MGR /MY_EMP/MY_MGR
(2) If you try to write on a table and all of its constraints in a file and do it in a valid order, the entire solution is probably wrong. It is impossible, for example, to generate the DDL for MY_EMP and MY_DEPT such as all instructions for a table come first, and all the instructions for the other are generated second. So even if NOCYCLE to avoid the error, you would end up with an invalid DDL script. If that's the problem, I would rethink the approach.
-Generate the DDL for all tables without constraint
-Can generate the DDL for all primary key constraints
-Can generate the DDL for all unique key constraints
-Can generate the DDL for all foreign key constraintsThis is not solidarity all the DOF for a given in the file object. But the SQL will be radically simpler writing - there will be no need to even look at the dependency graph.
Justin
-
How to find children and parent of a resource in the HQU
How to find children and parents of a resource in the HQU?
for example, there is a server, how can I find all its services and its platform?
by the way, where can I get a full HQU API doc? There is no description in detail in the Documentation of HQU:http://support.hyperic.com/display/hypcomm/HQU+DocumentationHello
You can use the ResourceCategory.getPlatform () method to get the parent platform and you can use Resource.getViewableChildren () to the children. Here is a very basic example which comes out in the server.log:
import org.hyperic.hq.hqu.rendit.metaclass.ResourceCategory
import org.hyperic.hq.hqu.rendit.helpers.ResourceHelper
imports org.hyperic.hq.authz.server.session.AuthzSubjectManagerEJBImpl AuthzMandef authzMan = AuthzMan.one
def Overlord = authzMan.overlordPojo
def rHelper = new ResourceHelper (overlord)def resource = rHelper.find (server: 12226)
println ("" Resource: "+ resource.name +" is a child of ' + ResourceCategory.getPlatform (resource) .name + "and has children:" ")
resource.getViewableChildren (overlord) .every child {-->
println (child.name + "\n")
}As far as documentation goes, what you see on this page is all that is available at this time. I use the code source HQApi as reference when I can't find anything in the docs.
-
How to find the Parent Machine to a linked Clone?
Hello
I deployed a few clones using Lab manager, now, I wanted to find out how the clone Parent deployed to find?
I checked in the VM, for each child VM properties, is to show the string length... I want to see information such as (uses or used by types)... Child uses clone Parent or Parent clone is used by 'x' number of clones of children...
Please tell me how to find it?
Kind regards
Esxvmuser
Hey Buddy,
Open your configuration. You will see a list of all the VMS in your configuration.
There is a field called 'model '. This is your parent VM.
-
How to find the serial number of the processor in the MacBook pro s serial number? I have a dead MacBook that was given for service to a third party. I doubt that they have replaced the original parts. Help, please. Thank you
As far as I KNOW, the serial number of the MacBook does not have the serial number of the processor.
-
extract the child records of their specific parent folder
Hi all
The following query shows these records that I wanted to but I want to extract the child records with their specific parent folder for the new scenario. I want to choose which set of these documents that belong to store under inventory.
Select rt.transaction_id, rt.parent_transaction_id parent_id, trunc (rt.transaction_date) receipt_date
(, rsh.receipt_num, rsh.attribute13 grn_num,rt.subinventory,SYS_CONNECT_BY_PATH(rt.subinventory,'/') "road".
of rcv_transactions rt
rcv_shipment_headers rsh
where rt.shipment_header_id = rsh.shipment_header_id
start with rt.parent_transaction_id =-1
connect prior rt.transaction_id = rt.parent_transaction_id
Brothers and SŒURS of ORDER BY rt.subinventory
.
Please help to extract.
Hello
If all you want are the lines with sub_inventory = "STORE", and their ancestors, then you can simply do this:
SELECT *.
OF subinventory
START WITH sub_inventroy = "STORE".
CONNECTION BY transaction_id = parent_id PRIOR
ORDER BY transaction_id;
No need of subqueries or analytical functions. You can even no need for the ORDER BY clause.
-
How to find the age of a child and snapshot number snapshot for a virtual machine.
Hi all
How to find the age of a snapshot for a virtual machine child count and snapshot.
This code snippet should help... Assuming that you have the following entries:
VM (VC:VirtualMachine)
snapshot (VC:VirtualMachineSnapshot)
System.log("====== Snapshot details for VM: "+snapshot.config.name+" ======"); var snapshotTrees = vm.snapshot.rootSnapshotList; System.log("Snapshot Tree Count: "+snapshotTrees.length); for each (snapshotTree in snapshotTrees){ showSnapshotInfo(snapshotTree, snapshot); } function showSnapshotInfo(snapshotTree, selectedSnapshot){ if(selectedSnapshot == snapshotTree.snapshot){ System.log("===================="); System.log("Name: "+snapshotTree.name); System.log("Id: "+snapshotTree.id); System.log("Description: "+snapshotTree.description); System.log("createTime: "+snapshotTree.createTime); System.log("quiesced: "+snapshotTree.quiesced); System.log("replaySupported: "+snapshotTree.replaySupported); System.log("backupManifest: "+snapshotTree.backupManifest); System.log("snapshot id: "+snapshotTree.snapshot.id); System.log("state: "+snapshotTree.state.value); var childSnapshotList = snapshotTree.childSnapshotList; if(childSnapshotList != null){ System.log("childSnapshotList length: "+snapshotTree.childSnapshotList.length); } System.log(""); } if(snapshotTree.childSnapshotList != null){ System.log("Children found: "+snapshotTree.childSnapshotList.length); for each (childSnapshotTree in snapshotTree.childSnapshotList){ showSnapshotInfo(childSnapshotTree, selectedSnapshot); } } }
During the passage of one of my virtual machines, here is an example of output I get:
[2014-06-12 15:19:21.493] [I] Snapshot Tree Count: 1 [2014-06-12 15:19:21.493] [I] ==================== [2014-06-12 15:19:21.494] [I] Name: before upgrade to 5.0.1 [2014-06-12 15:19:21.494] [I] Id: 31 [2014-06-12 15:19:21.494] [I] Description: [2014-06-12 15:19:21.495] [I] createTime: Mon Mar 19 2012 13:48:57 GMT-0400 (EDT) [2014-06-12 15:19:21.495] [I] quiesced: false [2014-06-12 15:19:21.495] [I] replaySupported: null [2014-06-12 15:19:21.495] [I] backupManifest: null [2014-06-12 15:19:21.496] [I] snapshot id: snapshot-83 [2014-06-12 15:19:21.496] [I] state: poweredOff [2014-06-12 15:19:21.496] [I] childSnapshotList length: 1 [2014-06-12 15:19:21.496] [I] [2014-06-12 15:19:21.497] [I] ==================== [2014-06-12 15:19:21.497] [I] Name: Before 5.1 upgrade [2014-06-12 15:19:21.497] [I] Id: 36 [2014-06-12 15:19:21.497] [I] Description: [2014-06-12 15:19:21.498] [I] createTime: Fri Sep 21 2012 21:59:58 GMT-0400 (EDT) [2014-06-12 15:19:21.498] [I] quiesced: false [2014-06-12 15:19:21.498] [I] replaySupported: null [2014-06-12 15:19:21.498] [I] backupManifest: null [2014-06-12 15:19:21.499] [I] snapshot id: snapshot-84 [2014-06-12 15:19:21.499] [I] state: poweredOff [2014-06-12 15:19:21.499] [I] childSnapshotList length: 1 [2014-06-12 15:19:21.499] [I] [2014-06-12 15:19:21.500] [I] ==================== [2014-06-12 15:19:21.500] [I] Name: Before Named Instance [2014-06-12 15:19:21.500] [I] Id: 37 [2014-06-12 15:19:21.501] [I] Description: [2014-06-12 15:19:21.501] [I] createTime: Mon Nov 11 2013 13:40:46 GMT-0500 (EST) [2014-06-12 15:19:21.501] [I] quiesced: false [2014-06-12 15:19:21.501] [I] replaySupported: null [2014-06-12 15:19:21.502] [I] backupManifest: null [2014-06-12 15:19:21.502] [I] snapshot id: snapshot-236 [2014-06-12 15:19:21.502] [I] state: poweredOff [2014-06-12 15:19:21.502] [I]
-
Can someone advise me something in Lightroom please CC. When I export files once after you have finished the adjustments etc. and I click 'Save with the previous' - how to find where it was recorded, if I forgot the last folder saved to?
I guess you mean "Export with previous. If so, open the export page. It will be defined as "precedent".
-
How to find a specific record in what data file?
Hi all
The basic version: 11 GR 2
I am inserting a table a record called "xx". and the table is in a tablespace that has lets say 10 files of data. How to find the data file which stores this record "xx".
Thank you
ArunArun wrote:
Yes... I get file_id for three data files... How to find the exact?If the tablespace contains multiple data files and data in the table can be in the data files.
And to find the ID of the particular LINE belongs to the data file, you must play with package
SQL > select dbms_rowid.rowid_to_absolute_fno (rowid, 'SCHEMANAME', 'TABLENAME') of tablename;
Maybe you are looking for
-
Why all my music on my iphone is messed up. It is show another work of songs. I've tried everything. removal of the song, and then time. reset. is there a problem?
-
Identify the computer IP addresses
Hello world How to identify individual IP addresses of the computer and confirm my own? How to identify the geographical region/city of the different IP addresses? IP addresses seem to have 9 numbers - XX. XX. XX.XXX - Sign these individual computers
-
HP Photosmart 6521: Can find photo tray option when printing
I bought a HP Photosmart 6521 today, part of the family 652 x. I set up via the USB cable on my old Mac that is running Leopard 10.7. The printer software is automatically downloaded and the printer set up like a dream. Wifi link to my Wifi networ
-
Windows XP - grey wallpaper - cannot browse
Want to change the wallpaper from a personal photo to a different personal photo, but the button is gray out or inactive. The substantive title on the list of built-in backgrounds is also gray out or inactive. Can't choose one of the settings in th
-
So whenever I try to connect my Samsung Galaxy S4 active on my Windows Vista computer all it say is that is install the driver software of device, then it will say software successfully installed. So I'll start button, and then the computer so I can