0

I tried to create the parent and child tables as follows:

CREATE SEQUENCE ProcessLogId;

CREATE TABLE ProcessLog
(
ProcessLogId NUMBER DEFAULT ProcessLogId.NEXTVAL NOT NULL ,
ProcessName VARCHAR(20),
ProcessStatus VARCHAR(20),
StartTime DATE ,
EndTime DATE,
CreatedOn DATE DEFAULT (SYSDATE) NOT NULL,
CreatedBy VARCHAR(45) DEFAULT USER NOT NULL,
CONSTRAINT PK_ProcessLog PRIMARY KEY(ProcessLogId)
);

CREATE SEQUENCE SourceLogId;

CREATE TABLE SourceLog
(
SourceLogId    NUMBER DEFAULT SourceLogId.NEXTVAL NOT NULL ,
ProcessLogId    NUMBER NULL,
SourceName    VARCHAR(512) NOT NULL,
TotalRowCount    INT,
Status    VARCHAR(20),
StartTime    DATE,
EndTime    DATE
CONSTRAINT PK_SourceLogId PRIMARY KEY(SourceLogId),
CONSTRAINT CK_SourceLog_Status CHECK (Status='S' OR Status='F' OR Status='I'),
CONSTRAINT FK_SourceLog_ProcessLog FOREIGN KEY (ProcessLogId) REFERENCES ProcessLog(ProcessLogId)
);

And I have created two procedures to insert the records:

CREATE OR REPLACE PROCEDURE GetProcessLogId
(
ProcessName IN VARCHAR,ProcessLogId OUT INT)
AS
BEGIN
    INSERT INTO PROCESSLOG
           (ProcessName
           ,ProcessStatus
           ,StartTime)               

    VALUES(ProcessName
           ,'I'
           ,SYSDATE)
    RETURNING ProcessLogId INTO ProcessLogId;

END;

CREATE OR REPLACE PROCEDURE GetSourceLogId
(ProcessLogId IN NUMBER,SourceName IN VARCHAR,SourceLogId OUT NUMBER)
AS
BEGIN   

    INSERT INTO SourceLog
            (ProcessLogId
            ,SourceName
            ,Status
            ,StartTime)        
    VALUES  (ProcessLogId
            ,SourceName
            ,'I'
            ,SYSDATE)
    RETURNING SourceLogId INTO SourceLogId;
END; 

I have created the SSIS package to call these two procedures. Parent ProcessLog records are getting inserted successfully. But for the child table procedure I'm getting following error:

"[Execute SQL Task] Error: Executing the query "BEGIN GetSourceLogId(?,?,?output); end;" failed with the following error: "ORA-02291: integrity constraint (PATIENTMDR.FK_SOURCELOG_PROCESSLOG) violated - parent key not found ORA-06512: at "PATIENTMDR.GETSOURCELOGID", line 6 ORA-06512: at line 1". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly."

My SSIS package contains two ExecuteSQL tasks. In the first task I have called the GetProcessLogId procedure:

BEGIN
GetProcessLogId(?,?output);
end;

In the second task I have called GetSourceLogId procedure:

BEGIN
GetSourceLogId(?,?,?output);
end;

I have four variables, var_processlogid, var_processname, var_sourcelogid and var_sourcename.

I have assigned values to the first two, var_processname = 'Process1' and var_sourcename = 'Source1'; and I have assigned proper variables in perameter mapping section.

I have checked all the constraints. I have not been able to solve the problem. What am I doing wrong?

7
  • Are you sure that (a) your call to GetSourceLogId is passing the PK ID obtained from the first call; and (b) both calls are happening in the same DB session )or the first call is being committed)? Showing the code that calls both procedures might be helpful.
    – Alex Poole
    Nov 4, 2015 at 9:37
  • This is only going to work if you call first GetProcessLogId, capture its output and reuse it in GetSourceLogId per record in an OLE DB Command in a data flow. You can't call GetProcessLogId for 100 records and after that call GetSourceLogId. Is that what you're doing? It would help if you explained your SSIS workflow.
    – Nick.Mc
    Nov 4, 2015 at 9:40
  • I have two execute SQL task. In first one i have called first procedure , the code is: BEGIN GetProcessLogId(?,?output); end; I have 4 variables var_processlogid,var_processname,var_sourcelogid,var_sourcename. in 2nd ExecuteSQL task, I have code like BEGIN GetSourceLogId(?,?,?output); end; and mapped appropriate variable in perameter mapping section. Nov 4, 2015 at 9:42
  • Please add code and significant new information as an edit to the question rather than as a comment. I'm not familiar with SSIS, are the tasks in separate Oracle sessions?
    – Alex Poole
    Nov 4, 2015 at 9:46
  • Error message show no value have passed to GetSourceLogId procedure. Could you show the main Procedure that call both of procedures? or you can test to print the parameters before call GetSourceLogId procedure. Nov 4, 2015 at 9:59

1 Answer 1

1

You must be passing a bad ProcessLogIdto GetSourceLogId (which is BTW named strangely, this procedure primarily inserts a row and should be named accordingly). Since you didn't post the call to GetSourceLogId, I can't tell where you went wrong.

Try to remove the FK_SourceLog_ProcessLog constaint. Then your inserts should succeed. Then inspect what you have in SourceLog. No doubt you will find ProcessLogIds there, which have no correspondence in ProcessLog. Then things should become clear.

3
  • If I remove FK_SourceLog_ProcessLog constaint , then in SourceLog table,ProcessLogId will be null. Nov 4, 2015 at 9:59
  • @user3607647 - then you are not passing the process log ID retrieved from the first call.
    – Alex Poole
    Nov 4, 2015 at 10:27
  • In my SSIS package, I have not assigned the output direction to ProcessLogId. It causes the issue. Thank you so much! Nov 4, 2015 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.