Deletion of child records linked to parent records to be deleted etc..

'Combined with WHEN OTHERS, SQLCODE provides a way for you to handle different, specific exceptions without having to use EXCEPTION_INIT pragma. In the next example, I trap two parent child exceptions, -2292 and -2291, and, then take an action appropriate to each situation:
PROCEDURE delete_company (company_id_in IN NUMBER)
IS
BEGIN
DELETE FROM company where company_id = company_id_in;
EXCEPTION
WHEN OTHERS THEN
DECLARE
error_code NUMBER := SQLCODE;
error_msg VARCHAR2(512) := SQLERM;
BEGIN
IF error_code = -2292 THEN
/*Child records found. Delete these too */
DELETE FROM employee WHERE company_id = company_id_in;
/* Now delete parent again */
DELETE FROM company WHERE company_id = company_id_in;
ELSIF error_code = -2291 THEN
/* Parent key not found */
DBMS_OUTPUT_PUT_LINE('Invalid company id' || TO_CHAR(company_id_in));
ELSE
/* This is like a WHEN OTHERS inside a WHEN OTHERS */
DBMS_OUTPUT_PUT_LINE('Error deleting company, error: ' || error_msg
END IF;
END;
END delete_company;
Sourced from Oracle PL/SQL Programming (3rd edition) P.143
1. Are error_code and error_msg assigned automatically or do I have to include assignments? If yes, how?
2. Where do I get a list of commonly caught Oracle error codes and similar code snippets used for business logic?
3. How would you deal with the situation where you detect a parent while you are deleting a child record? Just warn the user and log it hoping the DBA will review the logs?
4. I work within a project where I could not query any parent-child relationships, using, amongst other queries the following query, and, this means that the programming team might not be creating these relationships within the database (Oracle 11g).
What are the technical risks?
Could I be omitting something, because it seems quite incredible to me that parent-child relationships are not in place?
SELECT a.table_name,
a.column_name,
a.constraint_name,
c.owner
FROM ALL_CONS_COLUMNS A, ALL_CONSTRAINTS C
where A.CONSTRAINT_NAME = C.CONSTRAINT_NAME
and a.table_name=:TableName
and C.CONSTRAINT_TYPE = 'R'
Sourced from http://stackoverflow.com/questions/1729996/list-of-foreign-keys-and-the-tables-they-reference

This is bad code, very very bad code. Throw it away and start with a clear idea of what you want to do.
Why is this code very very bad? Because it uses WHEN OTHERS not followed by a RAISE.
Why is this code bad code? Because it uses one WHEN clause instead of several.
Here is an example for handling multiple exceptions:
http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/errors.htm#BABFBHGA
If your error code does not have a predefined name, define the name yourself:
http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/errors.htm#BABIIEFC
If you keep the WHEN OTHERS at the end, be sure to add RAISE so the exception still exists. If you don't, Oracle will not do the automatic rollback it should be doing.
To answer your question about parent-child relationships, it is very important to have them. They stop you deleting a parent that has children, but they do not stop you from deleting children.

Similar Messages

  • FRM-41106 You cannot create records without a parent record.

    Hello!
    Forms 6i.
    I have a Parent-Detail-Relationship. At the Detail-Block a "When-create-record" sets some default values on the Detail-Block.
    I got error "FRM-41106 You cannot create records without a parent record" when the Parent-Block executes a execute_query.
    I debuged the problem an found out, that the error appears in the standard-programunit "Clear_All_Master_Details".
    The error appears, when the code is deleting the detail-block "code: Clear_Block(NO_VALIDATE)".
    This is strange: The error appears only when I uses the "When-create-record"-trigger on the detail-block.
    If a comment out the trigger, no error appears.
    Why Is a "When-create-record"-trigger initiated when deleting the detail-block?
    Default-Code of "Clear_All_Master_Details":
    -- Clear all the detail blocks for this master without
    -- any further asking to commit.
    currel := Get_Block_Property(trigblk, FIRST_MASTER_RELATION);
    WHILE currel IS NOT NULL LOOP
    curdtl := Get_Relation_Property(currel, DETAIL_NAME);
    IF Get_Block_Property(curdtl, STATUS) <> 'NEW' THEN
    Go_Block(curdtl);
    Check_Package_Failure;
    Error appear here----> Clear_Block(NO_VALIDATE);
    IF :System.Block_Status <> 'NEW' THEN
    RAISE Form_Trigger_Failure;
    END IF;
    END IF;
    currel := Get_Relation_Property(currel, NEXT_MASTER_RELATION);
    END LOOP;
    Thx in advance,
    Wolfgang

    Wolfgang,
    To be honest, I've always done this kind of thing in the Pre-Inse rt or Pre-Upda te triggers. Why is it so important for the user to see the value of these field BEFORE the IN SERT or UPDAT E? Once the record is commited, they will see these values in your form. In my experience - users are typically satisfied with this approach. If your users are not OK with this approach, perhaps you could us a When-Validate-Record trigger instead of the When-Create-Record trigger.
    I think the When-Create-Record option would still work, but your code will need a little tweak. Give the following a try:
       IF ( NVL(:termin.best_nr,'MSTR') = NVL(:pos.best_nr,'DTL')
            AND NVL(:termin.best_jj,'MSTR') = NVL(:pos.best_jj,'DTL')
            AND NVL(:termin.best_pos,'MSTR') = NVL(:pos.best_pos,'DTL') ) THEN
           <<...set_values..>>
       END IF;Remember, NULL values do not always get evaluated correctly so it is always best to use the NVL function to ensure fields are evaluated correctly.
    BTW, you indicated that you ran DEBUG on your trigger, when your IF statement was evaluated did the "set_Values" section of your code run? If it didn't - do you have other code in your WCR trigger that is setting values outside of your IF statement?
    Craig...

  • Find child record of a parent record

    Hi,
    I need to find the child recond of a parent party and if that child also have some
    child then I need to find again and this process will go untill no child record
    found(child is null)
    I am trying to do it by the help of hierarchical query.
    can anyone please help and tell me how can I do that and how can I handle if a parent have multiple childs.
    Mohan

    It is always helpful to provide the following:
    1. Oracle version (SELECT * FROM V$VERSION)
    2. Sample data in the form of CREATE / INSERT statements.
    3. Expected output
    4. Explanation of expected output (A.K.A. "business logic")
    5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.
    Also see the third post in this thread:
    {thread:id=2174552}
    This would probably be better suited in the {forum:id=75} forum.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to remove  child query link from parent query for RRI

    Hi Floks,
    Long back we have created one RRI report(which is having parent child relation).Currently i wanted to remove this link or relation (i.e remove child report) between them.
    I tried From  t-code RSBBS but i could n't.  Please give me some inputs to fix this.
    Regards,
    Satya.

    Hi Satya,
    In the TCode RSBBS ,did u try deleting the assignments itself ..........save it and transport it ...........
    Rgds
    SVU123

  • Delete the parent records and child table records at a time

    hi all;
    I am facing the pbm like to delete the all records in child table and corresponding records in parent table at a time. so I want to delete the all the records in child table and corresponding parent records in parent table by using single SQL query. plz help me
    Thanks in advance

    You want to use one single SQL statement to delete the child records in a table and the corresponding master records in the master table??
    That's not quite possible with a single SQL, of course unless you are talking about Oracle Forms, where you have a relation and set the delete behavior to Cascading, like said in the above posts.
    Tony

  • How to obtain parent record from child record in relationship using API

    Hi,
    I have a record in the main table that is the child in a parent/child relationship to another main table record.  Using the Java API, how would I obtain the parent record in the relationship where I am starting with the child record?  In the API there seems to just be calls for getChildren, but not a getParent type call.
    Appreciate any immediate help that can be provided.
    Thanks,
    Eddie

    Hi Eddie,
    Please follow the below steps to retrieve only parents of a child Record.
    1. Create RetrieveRelationshipsCommand.
    2. Set the parameter RelationshipId.
    3. Set the parameter Anchor Record and Anchor Record Id. In this case the child record for which parents records to be retrieved.
    4. Set the parameter setGetChildren as false . This retrieves only the parent records for the specified child reocrd.
    5. Execute the RetrieveRelationshipsCommand.
    6. Retrieve member records from above step.
    Hope it helps
    Regards,
    Neeharika

  • Problem with Retrieving Parent records

    Hi
    I am facing some problem with Relation ship tables
    I am able to retrieve all child relation record by using Parent record id, but the other why around is not working that is
    I am unable to retrieve  all parent records by using a child record.
    Please can you help out this..
    find the below sample method which i was trying
    public HashMap<String, Record[]> getMemberRecords(Record[] rec,
                   RetrieveRelationshipsCommand relation,
                   RepositorySchemaEx repositorySchema, String code,
                   HashMap<String, Record[]> returnMap) throws MDMException {
              LOG.debug("calling getMemberRecords");
              HashMap<String, Record[]> returnVal = returnMap;
              LOG.debug("Assigning returnType to default HashMap.");
              try {
                   for (int recordCount = 0; recordCount < rec.length; recordCount++) {
                        LOG.debug("For recordCount = " + recordCount);
                        Record tempRec = rec[recordCount];
                        relation.setAnchorRecord(tempRec);
                        LOG.debug(" setting AnchorRecord = " + tempRec);
                        relation.setLoadRecords(true);
                        LOG.debug(" setting LoadRecords = " + true);
                        relation.setGetChildren(false);
                        LOG.debug(" setGetChildren has setup with  = " + true);
                        relation.setAnchorRecordId(tempRec.getId());
                        LOG.debug(" setting AnchorRecordId = " + tempRec.getId());
                        relation.setRelationshipId(repositorySchema
                                  .getRelationshipId(code));
                        LOG.debug("Before execution relation execute.");
                        relation.execute();
                        LOG.debug("After execution relation execute.");
                        RelationshipGroup group = relation.getRelationshipGroup();
                        LOG.debug("Retrieved Relationship Group.");
                        Relationship[] relat = group.getMembers();
                        LOG.debug("Length = "+relat.length);
                        Record[] tempRecords = null;
                        if (relat != null) {
                             int length = relat.length;
                             LOG.debug("Length = "+length);
                             tempRecords = new Record[length];
                             for (int count = 0; count < length; count++) {
                                  tempRecords[count] = relat[count].getMemberRecord();
                        if (tempRecords != null) {
                             LOG
                                       .info("Records size is not equal to Null So Calling recursive getMemberRecords.");
                             returnMap = getMemberRecords(tempRecords, relation,
                                       repositorySchema, code, returnMap);
                        LOG
                                  .debug("Setting HashMap Value Values with Parent ID, records[]");
                        returnVal.put(tempRec.getId().getString(), tempRecords);
              } catch (SessionException se) {
                   MDMException exception = new MDMException();
                   ErrorContext ec = new ErrorContext();
                   ec.setErrorMessage(se.getMessage());
                   ec.setErrorCode("MetadataException : " + se);
                   LOG.fatal(se, se.getCause());
                   se.printStackTrace();
                   exception.setContext(ec);
                   throw exception;
              } catch (IllegalArgumentException iae) {
                   MDMException exception = new MDMException();
                   ErrorContext ec = new ErrorContext();
                   ec.setErrorMessage(iae.getMessage());
                   ec.setErrorCode("MetadataException : " + iae);
                   LOG.fatal(iae, iae.getCause());
                   iae.printStackTrace();
                   exception.setContext(ec);
                   throw exception;
              } catch (CommandException ce) {
                   MDMException exception = new MDMException();
                   ErrorContext ec = new ErrorContext();
                   ec.setErrorMessage(ce.getMessage());
                   LOG.fatal(ce, ce.getCause());
                   ce.printStackTrace();
                   exception.setContext(ec);
                   throw exception;
              LOG.debug("Before returning from getMemberRecords");
              return returnVal;

    Hi
    I am facing some problem with Relation ship tables
    I am able to retrieve all child relation record by using Parent record id, but the other why around is not working that is
    I am unable to retrieve  all parent records by using a child record.
    Please can you help out this..
    find the below sample method which i was trying
    public HashMap<String, Record[]> getMemberRecords(Record[] rec,
                   RetrieveRelationshipsCommand relation,
                   RepositorySchemaEx repositorySchema, String code,
                   HashMap<String, Record[]> returnMap) throws MDMException {
              LOG.debug("calling getMemberRecords");
              HashMap<String, Record[]> returnVal = returnMap;
              LOG.debug("Assigning returnType to default HashMap.");
              try {
                   for (int recordCount = 0; recordCount < rec.length; recordCount++) {
                        LOG.debug("For recordCount = " + recordCount);
                        Record tempRec = rec[recordCount];
                        relation.setAnchorRecord(tempRec);
                        LOG.debug(" setting AnchorRecord = " + tempRec);
                        relation.setLoadRecords(true);
                        LOG.debug(" setting LoadRecords = " + true);
                        relation.setGetChildren(false);
                        LOG.debug(" setGetChildren has setup with  = " + true);
                        relation.setAnchorRecordId(tempRec.getId());
                        LOG.debug(" setting AnchorRecordId = " + tempRec.getId());
                        relation.setRelationshipId(repositorySchema
                                  .getRelationshipId(code));
                        LOG.debug("Before execution relation execute.");
                        relation.execute();
                        LOG.debug("After execution relation execute.");
                        RelationshipGroup group = relation.getRelationshipGroup();
                        LOG.debug("Retrieved Relationship Group.");
                        Relationship[] relat = group.getMembers();
                        LOG.debug("Length = "+relat.length);
                        Record[] tempRecords = null;
                        if (relat != null) {
                             int length = relat.length;
                             LOG.debug("Length = "+length);
                             tempRecords = new Record[length];
                             for (int count = 0; count < length; count++) {
                                  tempRecords[count] = relat[count].getMemberRecord();
                        if (tempRecords != null) {
                             LOG
                                       .info("Records size is not equal to Null So Calling recursive getMemberRecords.");
                             returnMap = getMemberRecords(tempRecords, relation,
                                       repositorySchema, code, returnMap);
                        LOG
                                  .debug("Setting HashMap Value Values with Parent ID, records[]");
                        returnVal.put(tempRec.getId().getString(), tempRecords);
              } catch (SessionException se) {
                   MDMException exception = new MDMException();
                   ErrorContext ec = new ErrorContext();
                   ec.setErrorMessage(se.getMessage());
                   ec.setErrorCode("MetadataException : " + se);
                   LOG.fatal(se, se.getCause());
                   se.printStackTrace();
                   exception.setContext(ec);
                   throw exception;
              } catch (IllegalArgumentException iae) {
                   MDMException exception = new MDMException();
                   ErrorContext ec = new ErrorContext();
                   ec.setErrorMessage(iae.getMessage());
                   ec.setErrorCode("MetadataException : " + iae);
                   LOG.fatal(iae, iae.getCause());
                   iae.printStackTrace();
                   exception.setContext(ec);
                   throw exception;
              } catch (CommandException ce) {
                   MDMException exception = new MDMException();
                   ErrorContext ec = new ErrorContext();
                   ec.setErrorMessage(ce.getMessage());
                   LOG.fatal(ce, ce.getCause());
                   ce.printStackTrace();
                   exception.setContext(ec);
                   throw exception;
              LOG.debug("Before returning from getMemberRecords");
              return returnVal;

  • How do i delete albums/photos once linked to my business laptop?

    How do I delete albums/photos once linked to a former laptop?

    Delete them from what?
    Your iphone?
    The same way you put them there.  The sync process.  Open itunes, connect iphone, select what you want to be on the iphone, sync

  • How to delete the duplicate rows present in the parent table & insert the latest duplicate record into the parent table linked with the child table.

    I have a master table and i need to import the rows into the parent and child table.
    Master table name is Flatfile_Inventory
    Parent Table name is INVENTORY
    Child Tables name are INVENTORY_AMOUNT,INVENTORY_DETAILS,INVENTORY_VEHICLE,
    Error details will be goes to LOG_INVENTORY_ERROR
    I have 4 duplicate rows in the Flatfile_Inventory which i have already inserted in the Parent and child table.
    Again when i run the query using stored procedure,
    its tells that all the 4 rows are duplicate and will move to the Log_Inventory_Error.
    I need is if i have the duplicate rows in the flatfile_Inventory when i start inserting into the parent and child table the already inserted row have the unique ID i
    must identify it and delete that row in the both parent and chlid table.And latest row must get inserted into the Parent and child table from Flatfile_Inventory.
    Please help me to write the query i have attached the Full stored procedure Script..
    Arunraj Kumar

    Hi Santhosh,
    This is my Script.
    -- =============================================
    -- Stored Procedure for FLATFILE_INVENTORY
    -- =============================================
    -- Drop stored procedure if it already exists
       DROP PROCEDURE SP_Flatfile_Inventory
    GO
    CREATE PROCEDURE SP_Flatfile_Inventory
    AS
    --USE IconicMarketing
    GO
    DECLARE
    @FileType  varchar(50)  ,
    @ACDealerID  varchar(50)  ,
    @ClientDealerID  varchar(50)  ,
    @DMSType  varchar(50)  ,
    @StockNumber  varchar(50)  ,
    @InventoryDate  datetime  ,
    @StockType  varchar(100)  ,
    @DMSStatus  varchar(50)  ,
    @InvoicePrice  numeric(18, 2)  ,
    @CostPack  varchar(50)  ,
    @SalesCost  numeric(18, 2)  ,
    @HoldbackAmount  numeric(18, 2)  ,
    @ListPrice  numeric(18, 2)  ,
    @MSRP  varchar(max)  ,
    @LotLocation  varchar(50)  ,
    @TagLine  varchar(max)  ,
    @Certification  varchar(max)  ,
    @CertificationNumber  varchar(max)  ,
    @VehicleVIN  varchar(50)  ,
    @VehicleYear  bigint  ,
    @VehicleMake  varchar(50)  ,
    @VehicleModel  varchar(50)  ,
    @VehicleModelCode  varchar(50)  ,
    @VehicleTrim  varchar(50)  ,
    @VehicleSubTrimLevel  varchar(max)  ,
    @Classification  varchar(max)  ,
    @TypeCode  varchar(100)  ,
    @VehicleMileage  bigint  ,
    @EngineCylinderCount  bigint  ,
    @TransmissionType  varchar(50)  ,
    @VehicleExteriorColor  varchar(50)  ,
    @VehicleInteriorColor  varchar(50)  ,
    @CreatedDate  datetime  ,
    @LastModifiedDate  datetime  ,
    @ModifiedFlag  varchar(max)  ,
    @InteriorColorCode  varchar(50)  ,
    @ExteriorColorCode  varchar(50)  ,
    @PackageCode  varchar(50)  ,
    @CodedCost  varchar(50)  ,
    @Air  varchar(100)  ,
    @OrderType  varchar(max)  ,
    @AgeDays  bigint  ,
    @OutstandingRO  varchar(50)  ,
    @DlrAccessoryRetail  varchar(50)  ,
    @DlrAccessoryCost  varchar(max)  ,
    @DlrAccessoryDesc  varchar(max)  ,
    @ModelDesc  varchar(50)  ,
    @Memo1  varchar(1000)  ,
    @Memo2  varchar(max)  ,
    @Weight  varchar(max)  ,
    @FloorPlan  numeric(18, 2)  ,
    @Purchaser  varchar(max)  ,
    @PurchasedFrom  varchar(max)  ,
    @InternetPrice  varchar(50)  ,
    @InventoryAcctDollar  numeric(18, 2)  ,
    @VehicleType  varchar(50)  ,
    @DealerAccessoryCode  varchar(50)  ,
    @AllInventoryAcctDollar  numeric(18, 2)  ,
    @BestPrice  varchar(50)  ,
    @InStock  bigint  ,
    @AccountingMake  varchar(50)  ,
    @GasDiesel  varchar(max)  ,
    @BookValue  varchar(10)  ,
    @FactoryAccessoryDescription  varchar(max)  ,
    @TotalReturn  varchar(10)  ,
    @TotalCost  varchar(10)  ,
    @SS  varchar(max)  ,
    @VehicleBody  varchar(max)  ,
    @StandardEquipment  varchar(max)  ,
    @Account  varchar(max)  ,
    @CalculatedPrice  varchar(10)  ,
    @OriginalCost  varchar(10)  ,
    @AccessoryCore  varchar(10)  ,
    @OtherDollar  varchar(10)  ,
    @PrimaryBookValue  varchar(10)  ,
    @AmountDue  varchar(10)  ,
    @LicenseFee  varchar(10)  ,
    @ICompany  varchar(max)  ,
    @InvenAcct  varchar(max)  ,
    @Field23  varchar(max)  ,
    @Field24  varchar(max)  ,
    @SalesCode  varchar(max)  ,
    @BaseRetail  varchar(10)  ,
    @BaseInvAmt  varchar(10)  ,
    @CommPrice  varchar(10)  ,
    @Price1  varchar(10)  ,
    @Price2  varchar(10)  ,
    @StickerPrice  varchar(10)  ,
    @TotInvAmt  varchar(10)  ,
    @OptRetail  varchar(max)  ,
    @OptInvAmt  varchar(10)  ,
    @OptCost  varchar(10)  ,
    @Options  varchar(max)  ,
    @Category  varchar(max)  ,
    @Description  varchar(max)  ,
    @Engine  varchar(max)  ,
    @ModelType  varchar(max)  ,
    @FTCode  varchar(max)  ,
    @Wholesale  varchar(max)  ,
    @Retail  varchar(max)  ,
    @Draft  varchar(max)  ,
    @Inventoryid int;
    DECLARE Inventory_Cursor CURSOR FOR 
    SELECT * from [dbo].[FLATFILE_INVENTORY];
    OPEN Inventory_Cursor
    FETCH NEXT FROM Inventory_Cursor 
    INTO @FileType   ,
    @ACDealerID     ,
    @ClientDealerID     ,
    @DMSType     ,
    @StockNumber     ,
    @InventoryDate    ,
    @StockType    ,
    @DMSStatus     ,
    @InvoicePrice     ,
    @CostPack     ,
    @SalesCost     ,
    @HoldbackAmount     ,
    @ListPrice     ,
    @MSRP     ,
    @LotLocation     ,
    @TagLine     ,
    @Certification     ,
    @CertificationNumber     ,
    @VehicleVIN     ,
    @VehicleYear     ,
    @VehicleMake     ,
    @VehicleModel     ,
    @VehicleModelCode     ,
    @VehicleTrim     ,
    @VehicleSubTrimLevel     ,
    @Classification     ,
    @TypeCode    ,
    @VehicleMileage     ,
    @EngineCylinderCount     ,
    @TransmissionType     ,
    @VehicleExteriorColor     ,
    @VehicleInteriorColor     ,
    @CreatedDate    ,
    @LastModifiedDate    ,
    @ModifiedFlag     ,
    @InteriorColorCode     ,
    @ExteriorColorCode     ,
    @PackageCode     ,
    @CodedCost     ,
    @Air    ,
    @OrderType     ,
    @AgeDays     ,
    @OutstandingRO     ,
    @DlrAccessoryRetail     ,
    @DlrAccessoryCost     ,
    @DlrAccessoryDesc     ,
    @ModelDesc     ,
    @Memo1 ,
    @Memo2     ,
    @Weight     ,
    @FloorPlan     ,
    @Purchaser     ,
    @PurchasedFrom     ,
    @InternetPrice     ,
    @InventoryAcctDollar     ,
    @VehicleType     ,
    @DealerAccessoryCode     ,
    @AllInventoryAcctDollar     ,
    @BestPrice     ,
    @InStock     ,
    @AccountingMake     ,
    @GasDiesel     ,
    @BookValue     ,
    @FactoryAccessoryDescription     ,
    @TotalReturn     ,
    @TotalCost     ,
    @SS     ,
    @VehicleBody     ,
    @StandardEquipment     ,
    @Account     ,
    @CalculatedPrice     ,
    @OriginalCost     ,
    @AccessoryCore     ,
    @OtherDollar     ,
    @PrimaryBookValue     ,
    @AmountDue     ,
    @LicenseFee     ,
    @ICompany     ,
    @InvenAcct     ,
    @Field23     ,
    @Field24     ,
    @SalesCode     ,
    @BaseRetail     ,
    @BaseInvAmt     ,
    @CommPrice     ,
    @Price1     ,
    @Price2     ,
    @StickerPrice     ,
    @TotInvAmt     ,
    @OptRetail     ,
    @OptInvAmt     ,
    @OptCost     ,
    @Options     ,
    @Category     ,
    @Description     ,
    @Engine     ,
    @ModelType     ,
    @FTCode     ,
    @Wholesale     ,
    @Retail     ,
    @Draft     ;
    WHILE @@FETCH_STATUS = 0
    BEGIN
        PRINT @VehicleVIN    ;
    -- ****************** insert into Inventory Table ***********
    INSERT INTO INVENTORY 
    IconicDealerID,
    StockNumber,
    DMSType,
    InventoryDate
    VALUES (@ClientDealerID,@StockNumber,@DMSType,@InventoryDate);
    set @Inventoryid = scope_identity();
    PRINT @Inventoryid;
    --Insert into Inventory_Details Table
    INSERT INTO [INVENTORY_DETAILS]
    InventoryID,
    StockType,
    DMSStatus,
    LotLocation,
    TagLine,
    Certification,
    CertificationNumber,
    CreatedDate,
    LastModifiedDate,
    ModifiedFlag,
    PackageCode,
    OrderType,
    AgeDays,
    OutstandingRO,
    Memo1,
    Memo2,
    Purchaser,
    PurchasedFrom,
    DealerAccessoryCode,
    InStock,
    AccountingMake,
    SS,
    Account,
    AccessoryCore,
    ICompany,
    InvenAcct,
    Field23,
    Field24,
    SalesCode,
    Draft,
    FTCode
    VALUES (
    @InventoryID,
    @StockType,
    @DMSStatus,
    @LotLocation,
    @TagLine,
    @Certification,
    @CertificationNumber,
    @CreatedDate,
    @LastModifiedDate,
    @ModifiedFlag,
    @PackageCode,
    @OrderType,
    @AgeDays,
    @OutstandingRO,
    @Memo1,
    @Memo2,
    @Purchaser,
    @PurchasedFrom,
    @DealerAccessoryCode,
    @InStock,
    @AccountingMake,
    @SS,
    @Account,
    @AccessoryCore,
    @ICompany,
    @InvenAcct,
    @Field23,
    @Field24,
    @SalesCode,
    @Draft,
    @FTCode
    --Insert into Inventory_Amount Table
    INSERT INTO [dbo].[INVENTORY_AMOUNT]
    InventoryID,
    AllInventoryAcctDollar,
    OtherDollar,
    PrimaryBookValue,
    AmountDue,
    LicenseFee,
    CalculatedPrice,
    OriginalCost,
    BookValue,
    TotalReturn,
    TotalCost,
    DlrAccessoryRetail,
    DlrAccessoryCost,
    DlrAccessoryDesc,
    InternetPrice,
    InventoryAcctDollar,
    BestPrice,
    Weight,
    FloorPlan,
    CodedCost,
    InvoicePrice,
    CostPack,
    SalesCost,
    HoldbackAmount,
    ListPrice,
    MSRP,
    BaseRetail,
    BaseInvAmt,
    CommPrice,
    Price1,
    Price2,
    StickerPrice,
    TotInvAmt,
    OptRetail,
    OptInvAmt,
    OptCost,
    Wholesale,
    Retail
    VALUES (
    @InventoryID,
    @AllInventoryAcctDollar,
    @OtherDollar,
    @PrimaryBookValue,
    @AmountDue,
    @LicenseFee,
    @CalculatedPrice,
    @OriginalCost,
    @BookValue,
    @TotalReturn,
    @TotalCost,
    @DlrAccessoryRetail,
    @DlrAccessoryCost,
    @DlrAccessoryDesc,
    @InternetPrice,
    @InventoryAcctDollar,
    @BestPrice,
    @Weight,
    @FloorPlan,
    @CodedCost,
    @InvoicePrice,
    @CostPack,
    @SalesCost,
    @HoldbackAmount,
    @ListPrice,
    @MSRP,
    @BaseRetail,
    @BaseInvAmt,
    @CommPrice,
    @Price1,
    @Price2,
    @StickerPrice,
    @TotInvAmt,
    @OptRetail,
    @OptInvAmt,
    @OptCost,
    @Wholesale,
    @Retail
    --Insert into Inventory_Vehicle Table
    INSERT INTO [dbo].[INVENTORY_VEHICLE]
    InventoryID,
    InteriorColorCode,
    ExteriorColorCode,
    Air,
    ModelDesc,
    VehicleType,
    VehicleVIN,
    VehicleYear,
    VehicleMake,
    VehicleModel,
    VehicleModelCode,
    VehicleTrim,
    VehicleSubTrimLevel,
    Classification,
    TypeCode,
    VehicleMileage
    VALUES (
    @InventoryID,
    @InteriorColorCode,
    @ExteriorColorCode,
    @Air,
    @ModelDesc,
    @VehicleType,
    @VehicleVIN,
    @VehicleYear,
    @VehicleMake,
    @VehicleModel,
    @VehicleModelCode,
    @VehicleTrim,
    @VehicleSubTrimLevel,
    @Classification,
    @TypeCode,
    @VehicleMileage
    -- Move cursor to Next record 
        FETCH NEXT FROM Inventory_Cursor 
    INTO @FileType   ,
    @ACDealerID     ,
    @ClientDealerID     ,
    @DMSType     ,
    @StockNumber     ,
    @InventoryDate    ,
    @StockType    ,
    @DMSStatus     ,
    @InvoicePrice     ,
    @CostPack     ,
    @SalesCost     ,
    @HoldbackAmount     ,
    @ListPrice     ,
    @MSRP     ,
    @LotLocation     ,
    @TagLine     ,
    @Certification     ,
    @CertificationNumber     ,
    @VehicleVIN     ,
    @VehicleYear     ,
    @VehicleMake     ,
    @VehicleModel     ,
    @VehicleModelCode     ,
    @VehicleTrim     ,
    @VehicleSubTrimLevel     ,
    @Classification     ,
    @TypeCode    ,
    @VehicleMileage     ,
    @EngineCylinderCount     ,
    @TransmissionType     ,
    @VehicleExteriorColor     ,
    @VehicleInteriorColor     ,
    @CreatedDate    ,
    @LastModifiedDate    ,
    @ModifiedFlag     ,
    @InteriorColorCode     ,
    @ExteriorColorCode     ,
    @PackageCode     ,
    @CodedCost     ,
    @Air    ,
    @OrderType     ,
    @AgeDays     ,
    @OutstandingRO     ,
    @DlrAccessoryRetail     ,
    @DlrAccessoryCost     ,
    @DlrAccessoryDesc     ,
    @ModelDesc     ,
    @Memo1 ,
    @Memo2     ,
    @Weight     ,
    @FloorPlan     ,
    @Purchaser     ,
    @PurchasedFrom     ,
    @InternetPrice     ,
    @InventoryAcctDollar     ,
    @VehicleType     ,
    @DealerAccessoryCode     ,
    @AllInventoryAcctDollar     ,
    @BestPrice     ,
    @InStock     ,
    @AccountingMake     ,
    @GasDiesel     ,
    @BookValue     ,
    @FactoryAccessoryDescription     ,
    @TotalReturn     ,
    @TotalCost     ,
    @SS     ,
    @VehicleBody     ,
    @StandardEquipment     ,
    @Account     ,
    @CalculatedPrice     ,
    @OriginalCost     ,
    @AccessoryCore     ,
    @OtherDollar     ,
    @PrimaryBookValue     ,
    @AmountDue     ,
    @LicenseFee     ,
    @ICompany     ,
    @InvenAcct     ,
    @Field23     ,
    @Field24     ,
    @SalesCode     ,
    @BaseRetail     ,
    @BaseInvAmt     ,
    @CommPrice     ,
    @Price1     ,
    @Price2     ,
    @StickerPrice     ,
    @TotInvAmt     ,
    @OptRetail     ,
    @OptInvAmt     ,
    @OptCost     ,
    @Options     ,
    @Category     ,
    @Description     ,
    @Engine     ,
    @ModelType     ,
    @FTCode     ,
    @Wholesale     ,
    @Retail     ,
    @Draft     ;
    END 
    CLOSE Inventory_Cursor;
    DEALLOCATE Inventory_Cursor;
    GO
    SET ANSI_PADDING OFF
    GO
    Arunraj Kumar

  • ADF,how to delete parent record and related child record without manual cod

    Hi All,
    I'm using 11g adf.
    I have one parent table PAR and two child table CHD1 , CHD2 respectively.
    I'm inserting values in three tables , making a form having add , delete and edit buttons.
    Issue when i want to delete a record from PAR table , it gives child table record exists . i have did manual coding to delete the child records with related to the selected parent table PAR.
    Is there any process in ADF to delete the child records with respective selected parent record with out manual coding.
    thanks in advance.

    http://download.oracle.com/docs/cd/E14571_01/web.1111/b31974/bcentities.htm#BABHFJFJ
    John

  • I want to delete parent record so that its child is automatically deleted

    Hi Gurus , i was trying to delete the child record as soon as parent is deleted.
    How do we do that?
    I can delete child 1st but it seems that there are lots of child data in different table.
    I have heard 'on delete cascade ' does that.
    Can you please help me out how to use that in delete statement???

    You should change your relationship to on delete = cascade. For example:
    alter table tb2 drop constraint fk;
    alter table tb2 add constraint fk foreign key (n) references tb1(n) on delete cascade;
    When you delete father table, will be deleted all children that have relationship like delete cascade.

  • How to find child records is exists before to delete parent records.

    Dear Everyone,
    I would like to ask you, is there any simple way to find child records is exists before to delete parent records.
    I have a master table defined primary key and I have referenced that as foreign key in many tables.
    I have used Delete_Record to delete but it isn't display the message 'child record exist' but it cleared the record from the form. So I need to know how to find child records is exists or not before to do delete_record so that I can display message in-case it exists.
    I do know we can able to check in every table matching the column manually, but what if we use 100 of tables then it is not possible to check manually.
    I am sure there must be simple way to find as how the oracle identifies when we execute delete query.
    Please help me on this.
    Thanks in advance.

    Simple solution is to run the query I have given for all child tables or to try a single query for all child tables withj something like:
    select <parent_key>
    from <parent_table>
    where <parent_key> in
              (select <foreign_key_1> from <child_table_1> union
               select <foreign_key_2> from <child_table_2> union
               ... );More complicate solution could be to change the foreign key constraints to cascade DELETE on parent table to child tables:
    SQL>
    SQL> create table p(x int primary key);
    Table created.
    SQL> create table c1(x1 int);
    Table created.
    SQL> create table c2(x2 int);
    Table created.
    SQL>
    SQL> alter table c1 add constraint fk1 foreign key(x1) references p;
    Table altered.
    SQL> alter table c2 add constraint fk2 foreign key (x2) references p;
    Table altered.
    SQL>
    SQL>
    SQL> insert into p values(1);
    1 row created.
    SQL> insert into c1 values(1);
    1 row created.
    SQL> insert into c2 values(1);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL>
    SQL> alter table c1 drop constraint fk1;
    Table altered.
    SQL> alter table c2 drop constraint fk2;
    Table altered.
    SQL>
    SQL> alter table c1 add constraint fk1 foreign key(x1) references p on delete cascade;
    Table altered.
    SQL> alter table c2 add constraint fk2 foreign key (x2) references p on delete cascade;
    Table altered.
    SQL>
    SQL> delete p where x=1;
    1 row deleted.
    SQL> commit;
    Commit complete.
    SQL> select * from p;
    no rows selected
    SQL> select * from c1;
    no rows selected
    SQL> select * from c2;
    no rows selected
    SQL>Edited by: P. Forstmann on 27 oct. 2011 14:01

  • Deadlock when deleting a not linked data record in a parent table

    Hello, who knows about this problem with Oracle 10g:
    Our installation of Oracle 10.2g behaves different from Oracle 9.2 concerning locking of data records:
    To prevent that different users edit a complex data record at the same time and store it, the user has to put
    the data record into the "edit mode" and we lock it with "Select CharFieldZ from TableX where ID = 1 for UPDATE NOWAIT".
    In this data record references (= foreign keys) to other tables are used; with foreign key constraints we
    prevent those data records of these tables from being deleted, which are used in data records of tableX: on
    deleting such a record Oracle gives an error message ORA-02292, which the application translates for the
    user: "You cannot delete this record, because it is used somewhere else".
    Now when locking data record A under Oracle 10.2g, which contains a foreign Key upon data record 1 of tableF,
    and trying to delete data record 2 of tableF, a deadlock appears, even when this data record is not used
    anywhere else.
    Further conditions:
    - Data record 2 was created before locking of data record A.
    - In the same session tableF was opened for reading before.
    Is there a parameter, which leads Oracle 10.2g to return to the former behavoir ?
    or: how is it possible to prevent a deadlock anyhow else ?
    Thanks in advance
    Lothar Weidl-Walther
    Germany
    Edited by: schatzag on 04.02.2009 14:22
    for easier demonstration the SQL-scripts:
    Installation:
    DELETE TableF;
    DELETE TableX;
    CREATE TABLE TableF
    ( ID INTEGER NOT NULL,
    NAME VARCHAR2(30 BYTE) NOT NULL);
    CREATE UNIQUE INDEX PK_TableF ON TableF(ID);
    ALTER TABLE TableF ADD CONSTRAINT PK_TableF PRIMARY KEY(ID);
    INSERT INTO TableF VALUES (1, 'Record1');
    INSERT INTO TableF VALUES (2, 'Record2');
    commit;
    CREATE TABLE TableX
    ( ID INTEGER NOT NULL,
    NAME VARCHAR2(30 BYTE) NOT NULL,
    CharFieldZ VARCHAR2(100 BYTE),
    TableF_ID INTEGER);
    ALTER TABLE TableX ADD (
    CONSTRAINT FK_TableX_TableF
    FOREIGN KEY (TableF_ID)
    REFERENCES TableF (ID));
    INSERT INTO TableX VALUES (1, 'ComplexRecord1', 'User1', 1);
    commit;
    Session1:
    SELECT CharFieldZ FROM TableX WHERE ID = 1 FOR UPDATE NOWAIT;
    SELECT * FROM TableF;
    Session2:
    DELETE FROM TableF WHERE ID = 2;
    Edited by: schatzag on 04.02.2009 14:26

    I'm not aware that the locking mechanism did change between Oracle 9i and 10g. Can you provide a simple and reproducable example?
    You current description is very "uncomplete", e.g. this statement would lock the full table, but I think that is not what your application does.
    Select CharFieldZ from TableX for UPDATE NOWAITAs Peter already mentioned you should check if there are any other differences between the databases. Let me mention just a few points that I can think of at the moment:
    * indexes
    * FK constraints with DELETE CASCADE
    * higher oracle block size (can lead to more ITL locks)
    Edited by: Sven W. on Feb 4, 2009 2:18 PM

  • Delete the parent record

    hi all,
    based on the thread i got the list of child tables.
    Re: to find the tables which is having link with particular table.
    no i have doubt in deletion process.
    My ultimate aim is to delete the bl_det records.
    let me explain with ex.
    i have table
    BL_DET --parent table with comp and ref as primary key
    which is having child rec.
    BL_CON --child of BL_DET(comp,ref) primary key comp,ref and serial
    BL_CON_PCK --is child of BL_CON(comp,ref,serial) primary key comp,ref,serial,pck_gp_srl,gp_srl.
    DELETE BL_CON_PCK
    WHERE BCK_COMP = :GLOBAL.comp
    AND BCK_REF = :parameter;
    DELETE FROM BL_CON
    WHERE BCR_COMP = :GLOBAL.comp
    AND BCR_REF = :paramter
    DELETE FROM BL_DET
    WHERE BL_COMP = :GLOBAL.comp
    AND BL_REF - :parameterwill delete the correct set of records.(my doubt area is delete statement written for the table BL_CON_PCK).
    Please tell me if i am wrong.
    Thanks..

    (my doubt area is delete statement written for the table BL_CON_PCK).Cannot understand your doubt. What is your doubt, are you getting any error while executing your code?
    To delete a record from parent table all child references must be deleted. So your delete statement appears right
    -- How delete should progress
    BL_CON_PCK >> BL_CON >> BL_DET
    {code}
    If you have created foreign constraint using ON DELETE CASCADE or ON DELETE SET NULL then you can straight away delete from parent table and all child references are deleted/set as null respectively. Read Oracle Documentation to see details
    Short demonstration
    {code:sql}
    SQL> CREATE TABLE A(a1 NUMBER PRIMARY KEY , a2 NUMBER);
    Table created
    SQL>  CREATE TABLE B(b1 NUMBER PRIMARY KEY , a1 NUMBER);
    Table created
    SQL>  CREATE TABLE C(c1 NUMBER, b1 NUMBER);
    Table created
    SQL>  ALTER TABLE B ADD CONSTRAINT FK_B FOREIGN KEY (a1) REFERENCES A ON DELETE CASCADE;
    Table altered
    SQL>  ALTER TABLE C ADD CONSTRAINT FK_C FOREIGN KEY (b1) REFERENCES B ON DELETE CASCADE;
    Table altered
    SQL>  INSERT INTO A VALUES (1,2);
    1 row inserted
    SQL>  INSERT INTO B VALUES (3,1);
    1 row inserted
    SQL>  INSERT INTO C VALUES (4,3);
    1 row inserted
    SQL>  SELECT * FROM A;
            A1         A2
             1          2
    SQL>  SELECT * FROM B;
            B1         A1
             3          1
    SQL>  SELECT * FROM C;
            C1         B1
             4          3
    SQL>  DELETE FROM A WHERE A1=1;
    1 row deleted
    SQL>  SELECT * FROM A;
            A1         A2
    SQL>  SELECT * FROM B;
            B1         A1
    SQL>  SELECT * FROM C;
            C1         B1
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Creating a Trigger for Deleting the records from a parent Table

    I am new to creating Trigger
    We will need several small tables that will be used to store any records that are deleted by the owner of the table. These will likely need a trigger where we would Delete from the parent table and on that Delete populate the child table with the previous record's data.
    Please give me a pseudo code for this
    Thanks
    John
    Edited by: user10750995 on Dec 30, 2008 9:06 AM

    Something like this:
    CREATE OR REPLACE TRIGGER trg_my_table_hist
    AFTER DELETE
    ON my_table
    FOR EACH ROW
    BEGIN
    INSERT INTO Hist_MyTable
    ( column1, column2, ..., DELETION_DATE)
    VALUES
    (:OLD.column1, :OLD.column2, ...., SYSDATE);
    END;
    /My_Table is your main table. When a row is deleted, the trigger will be fired and copy the deleted row to another table called Hist_My_Table. I'm supposing that the history table has all columns as they are defined in main tables plus a column named DELETION_DATE.
    My experience indicates that, probably, it's a good idea maintain update history and the user. But it depends on your requests.
    Regards,
    Miguel

Maybe you are looking for

  • Calendar sync help needed

    I am not allowed to use Outlook email at my workplace. It seems that I cannot use only the Outlook calendar to sync my Iphone without making it my primary email client. I need to have a desktop calendar of some sort at my work in order to manage my a

  • Personas and extended workflow notifications

    Hi Personas users. We have gone live with our first Personas business process which is effectively a service desk ticketing system based on PM notifications and equipment records. My users are very happy with the solution but as expected they want mo

  • What is Material master workflow

    Hi gurus , Can anybody explain what is Material master workflow & Function Module ?what is its use? Dev Edited by: dev .. on Oct 15, 2008 8:21 AM

  • Voicemail alert repeats when opening voicemail?

    This has been happening for so long I don't remember when it started, but maybe with iOS 8, or one of the subsequent updates?? The issue is this: I miss a call, and the caller leaves me a message. I have on of the older 'Classic' sounds set as my voi

  • Two identical cameras connected to one PC

    Hi, For stereo image capture I have two USB Logiech Pro 4000 cameras connected to my computer. However, the JMF Registry is not able to register both. I can work just with the firstly plugged one. Can anybody help me? Thanks.