ERROR-Logging of Stored Procedure (Stop / Going on after error + logging)

Hi @all,
I am using a Stored Procedure which is very simple:
=>The stored procedure is selecting many tousands of records from table1 + table2.
=> Some values (records) will be summarized (aggregated/group by).
=>After this selection and summarizing, this records will be deleted from table3 (if they exist in table3).
=>Then the selected records will be inserted in table3.
Now I want to do the following:
Is there a way to log the errors of the stored procedure?
For example, the stored procedure is copying many thousands of records.
If there is a problem on copying/ inserting a record to table3, then I want a error-log in a loggin_table.
Is there a way to write the error-logs from a stored procedure to a special table in database?
I want to do this in 2 ways:
1) On error the error is logged and the stored procedure is stopped.
2) On error the error is logged and the stored procedure is going on to insert/summarize the next record.
I don't know how I can get these errors of a stored procedure. Maybe it isn't possible? Or is it better to use a function?
Hope anyone can give me a hint?
Thanks a lot.
Best regards,
Tim

Hi
option one:
as i know you can have another table without primer key (log table).
then before you insert into table, select the record count using primary key. if it is duplicate then put those record into the table.
option two:
write the log into file.
declare
f utl_file.file_type;
s varchar2(200);
begin
f := utl_file.fopen('SAMPLEDATA','sample1.txt','R');
loop
utl_file.get_line(f,s);
dbms_output.put_line(s);
end loop;
exception
when NO_DATA_FOUND then
utl_file.fclose(f);
end;
refer : http://www.psoug.org/reference/OLD/utl_file.html
regards
upul.
Edited by: Upul Indika on Apr 9, 2009 12:45 PM

Similar Messages

  • Crystal Web Viewer executing stored procedure when going to next/prev page

    We are using VS.NET 2005 with SP1 to design reports and embed them in an aspnet web app. Some of them take a while to run, even in the designer. In the designer, however, next page and print operations are speedy. In the web viewer, next page and print operations are agonizingly slow.
    Viewing page 2 of a report seems to take about as long as viewing page
    1. After running SQL Profiler to trace the report, it is apparent that the entire report (Stored Procedure Call) is being re-run and just page 2 is being sent to the browser.
    Is this right?
    Shouldn't the report document be stored on the server or event the client so that the desired page can be loaded without having to hit the database again??
    We are using Business Objects Crystal Reports XI Release 2
    Do you have a sample code on this issue.

    It still did not work.  As you see my code has the Not Page.IsPostBack.  It still goes to the database to run the stored procedure over and over again.
    Do an example with more than 100 records to have multiple pages.  After you go to page #2, change your data by updating one of your fields that will not fit the criteria you are looking for.  In this example I changed the strPeriod from 1 to 2 and it gives you a blank report.
    update PeriodTable
    set fieldPeriod = 2
    < h3>Here is the code:</h3>
    Imports System.Xml
    Imports System.data
    Imports System.IO
    Imports System.Text
    Imports System.Configuration
    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    Partial Public Class viewreport
        Inherits System.Web.UI.Page
        Private _dsContacts As DataSet
        Dim strUser, strReport, strPeriod, strRegionType, strRegion, strDate, strUnit As String
        Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
            Try
                If Not Page.IsPostBack Then
                    If Not Page.User.Identity.IsAuthenticated Then
                        Response.Redirect("default.aspx")
                    End If
                    strUser = Request.QueryString("strUser")
                    strReport = Request.QueryString("strReport")
                    strPeriod = Request.QueryString("strPeriod")
                    strRegionType = Request.QueryString("strRegionType")
                    strRegion = Request.QueryString("strRegion")
                    strDate = Request.QueryString("strDate")
                    strUnit = Request.QueryString("strUnit")
                    If strUser <> "" And strReport <> "" Then
                        ConfigureCrystalReports()
                    Else
                        lblMessage.Text = "Values for the report where not received properly.<br /><br />" & strReport & "<br /><br />Please contact your Commissions Reporting Administrator<br /><br />"
                    End If
                End If
            Catch ex As Exception
                ErrorRoutine(ex, "Page_Load")
            End Try
        End Sub
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            GlobalCode.DisplayTitle("MetLife - Commissions Administration - Report Viewer", Page)
        End Sub
        Private Sub ConfigureCrystalReports()
            Try
                Dim i, j As Integer
                Dim ParameterValue As String
                _dsContacts = Nothing
                _dsContacts = New DataSet
                _dsContacts.ReadXml(Server.MapPath("XML\ReportFiles.xml"))
                For i = 0 To _dsContacts.Tables(0).Rows.Count - 1
                    If Trim(UCase(_dsContacts.Tables(0).Rows(i)("FileName").ToString)) = Trim(UCase(strReport)) Then
                        Dim conn As ConnectionInfo = New ConnectionInfo()
                        Dim reportPath As String = Server.MapPath("Reports/" & _dsContacts.Tables(0).Rows(i)("FileName").ToString)
                        If Not File.Exists(reportPath) Then
                            lblMessage.Text = "Report does not exists in our servers.<br /><br />" & reportPath & "<br /><br />Please contact your Commissions Reporting Administrator<br /><br />"
                            Exit Sub
                        End If
                        conn.DatabaseName = _dsContacts.Tables(0).Rows(i)("Database").ToString
                        conn.UserID = _dsContacts.Tables(0).Rows(i)("UserID").ToString
                        conn.Password = _dsContacts.Tables(0).Rows(i)("Password").ToString
                        Dim ConnInfo As New ConnectionInfo
                        With ConnInfo
                            .DatabaseName = _dsContacts.Tables(0).Rows(i)("Database").ToString
                            .UserID = _dsContacts.Tables(0).Rows(i)("UserID").ToString
                            .Password = _dsContacts.Tables(0).Rows(i)("Password").ToString
                        End With
                        ParameterValue = ""
                        CRViewer.ReportSource = reportPath
                        CRViewer.ParameterFieldInfo.Clear()
                        Dim ParamFields As ParameterFields = CRViewer.ParameterFieldInfo
                        Dim reportSeparation As New ReportDocument()
                        reportSeparation.Load(reportPath)
                        For j = 0 To reportSeparation.ParameterFields.Count - 1
                            Dim param As New ParameterField
                            param.Name = reportSeparation.ParameterFields.Item(j).Name
                            Select Case param.Name
                                Case "VRPTTYPE"
                                    ParameterValue = strRegionType
                                Case "VPARAM"
                                    ParameterValue = strRegion
                                Case "VUSER"
                                    ParameterValue = strUser
                                Case "VDATE"
                                    ParameterValue = strDate
                                Case "VUNIT"
                                    ParameterValue = strUnit
                                Case "VPERIOD"
                                    ParameterValue = strPeriod
                                Case Else
                                    lblMessage.Text = "<h1>Report has parameters not expected.</h1><br /><br /><h2>" & reportPath & "</h2><br /><br />Please contact your Commissions Reporting Administrator<br /><br />"
                                    Exit Sub
                            End Select
                            Dim param_Value As New ParameterDiscreteValue
                            param_Value.Value = ParameterValue
                            param.CurrentValues.Add(param_Value)
                            ParamFields.Add(param)
                        Next '
                        For Each cnInfo As TableLogOnInfo In CRViewer.LogOnInfo
                            cnInfo.ConnectionInfo = ConnInfo
                        Next
                        CRViewer.DataBind()
                        Exit Sub
                    End If
                Next
            Catch ex As Exception
                ErrorRoutine(ex, "ConfigureCrystalReports")
            End Try
        End Sub
        Public Sub ErrorRoutine(ByVal ex As Exception, ByVal Routine As String)
            GlobalCode.ErrorRoutine(ex, Routine, Master)
        End Sub
    End Class

  • Nested Try/Catch in a stored procedure going to outer

    I am using Service Broker to move data to a historical database and then delete it from the current table in a second stored procedure that gets the information passed to it; which I have working but what I am having trouble with is when there
    is an error in the second stored procedure rather than going to the catch in the second Stored procedure it goes back up to my first one.
    CREATE PROCEDURE [sp_PkgDelActivator_SB]
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    DECLARE @RecvReqDlgHandle UNIQUEIDENTIFIER;
    DECLARE @RecvReqMsg XML;
    DECLARE @RecvReqMsgName sysname;
    BEGIN TRY
    WHILE (1=1)
    BEGIN
    BEGIN TRAN
    --Get the top item on the queue.
    WAITFOR
    ( RECEIVE TOP(1)
    @RecvReqDlgHandle = conversation_handle,
    @RecvReqMsg = message_body,
    @RecvReqMsgName = message_type_name
    FROM DeleteReceiveQueue
    ), TIMEOUT 5000;
    IF (@@ROWCOUNT = 0)
    BEGIN
    ROLLBACK TRANSACTION;
    BREAK;
    END
    ELSE
    COMMIT TRAN
    EXEC sp_PkgDeleteHeap_SB
    @RecvReqDlgHandle = @RecvReqDlgHandle,
    @RecvReqMsg = @RecvReqMsg
    END
    END TRY
    BEGIN CATCH
    DECLARE @ERR_NR INT = ERROR_NUMBER(),
    @ERR_SVR_NR TINYINT = ERROR_SEVERITY(),
    @ERR_STT_NR TINYINT = ERROR_STATE(),
    @ERR_PRC_TE VARCHAR(50) = ERROR_PROCEDURE(),
    @ERR_LN_NR INT = ERROR_LINE(),
    @ERR_MSG_TE VARCHAR(1000) = ERROR_MESSAGE()
    IF @@TRANCOUNT > 0
    ROLLBACK TRAN
    INSERT INTO DB_ERR_LOG(
    ERR_NR,
    ERR_SVR_NR,
    ERR_STT_NR,
    ERR_PRC_TE,
    ERR_LN_NR,
    ERR_MSG_TE,
    LOG_DT)
    SELECT
    @ERR_NR,
    @ERR_SVR_NR,
    @ERR_STT_NR,
    @ERR_PRC_TE,
    @ERR_LN_NR,
    @ERR_MSG_TE,
    GETDATE()
    END CATCH
    END
    CREATE PROCEDURE [sp_PkgDeleteHeap_SB]
    @RecvReqDlgHandle UNIQUEIDENTIFIER,
    @RecvReqMsg XML
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    BEGIN TRY
    BEGIN TRANSACTION
    DECLARE @dtArrival date = 'gotten from somewhere else'
    IF @dtArrival BETWEEN '2014-07-01' AND '2014-09-30'
    BEGIN
    'Code to move and delete rows from a table'
    END
    ELSE IF @dtArrival BETWEEN '2015-01-01' AND '2015-03-31'
    BEGIN
    'Code to move and delete rows from a table'
    END
    ELSE IF @dtArrival BETWEEN '2015-04-01' AND '2015-06-30'
    BEGIN
    'Code to move and delete rows from a table'
    END
    END CONVERSATION @RecvReqDlgHandle WITH CLEANUP;
    END
    COMMIT TRAN
    END TRY
    BEGIN CATCH
    ROLLBACK TRAN
    DECLARE @ERR_NR INT = ERROR_NUMBER(),
    @ERR_SVR_NR TINYINT = ERROR_SEVERITY(),
    @ERR_STT_NR TINYINT = ERROR_STATE(),
    @ERR_PRC_TE VARCHAR(50) = ERROR_PROCEDURE(),
    @ERR_LN_NR INT = ERROR_LINE(),
    @ERR_MSG_TE VARCHAR(1000) = ERROR_MESSAGE()
    'Code to send the message back into the queue'
    INSERT INTO DB_ERR_LOG(
    ERR_NR,
    ERR_SVR_NR,
    ERR_STT_NR,
    ERR_PRC_TE,
    ERR_LN_NR,
    ERR_MSG_TE,
    LOG_DT)
    SELECT
    @ERR_NR,
    @ERR_SVR_NR,
    @ERR_STT_NR,
    @ERR_PRC_TE,
    @ERR_LN_NR,
    @ERR_MSG_TE,
    @END_TS
    END CATCH
    END
    Thanks for any help.
    Also if this is not the right area for this question I am sorry please tell me and I will try moving it to the right area.

    >>Please guide me how to create Stored Procedure and how to load datas into Flatfile table and from Flatfile Table to Parent and Child Table.
    Can you try loading the data using SSIS package ? If that's not an option , you could try OPENROWSET
    --from the linkUSE AdventureWorks2012;
    GO
    CREATE TABLE myTable(FileName nvarchar(60),
    FileType nvarchar(60), Document varbinary(max));
    GO
    INSERT INTO myTable(FileName, FileType, Document)
    SELECT 'Text1.txt' AS FileName,
    '.txt' AS FileType,
    * FROM OPENROWSET(BULK N'C:\Text1.txt', SINGLE_BLOB) AS Document;
    GO
    Satheesh
    My Blog |
    How to ask questions in technical forum

  • Multiple stored procedures using JDBC Adopter, Synchronous call

    Hello Guys,
    This is kind of different scenario,
    Here is the scenario (SQL Server -> XI -> Legacy)
    1.I want to trigger stored procedure (from XI to)
    2.Inside the stored procedure we are going to have multiple stored procedures.
    -Inside stored procedures
    SP1 -> It supposed to select the data from interface control table, if that is success
    SP2 -> Call some other stored procedures which can be select/insert/delete from different tables most of the cases it would be select, if that is success
         It should give results back (Response) to XI and with some output parameters like (status message, etc…)
    Next step I want send those results to target system which is legacy. If that is success
    Next step I should update entry in the Interface control table(which is in SQL Server) with success entry like (success message, current date, current time, interface name, username.) 
         If it fails any stage like while selecting data from interface control table which is SP1/ SP2 It should give error message back to XI(output parameters). XI is going to send Alerts/Mails to respective interface owners.
    This is my scenario can anybody help me on this what needs to be done to implement this scenario.

    Hi Murali,
    Anyway , altimately you are going to call one stored procedure and going to get one output. So it will not be a problem I think.
    Anyway it is required to introduce BPM here.
    <i>Next step I want send those results to target system which is legacy. If that is success</i>
    >>>You can make sure that message is recieved by legacy system. Because legacy systems like File systems will not support Application Acknowledgement. So here you can go with Transport Acknowledgement.
    From where will get Success messages like (current date etc) are you planning to take XI system date.. If so you can get this. And you can send the message to SQL.
    <i>If it fails any stage like while selecting data from interface control table which is SP1/ SP2 It should give error message back to XI(output parameters). XI is going to send Alerts/Mails to respective interface owners.</i>
    >>>For application errors like SP2 error etc, you need to get the Error Response from stored procedure itsel.
    Second option is you can go with Adapter Alerting, whenever any error in the Sender JDBC adapter.
    Anyway design/requirement should be perfect, before start the process here...
    Regards,
    Moorthy

  • Problems with datatypes while callling MS-SQL stored procedure

    Hi
        We have a stored procedure in MS-SQL server ( Sql Server 2000 ) that we are invoking from XI 3. ( SP18) using a receiver adapter communication channel . One of the parameters of the stored procedure has a decimal data type . In XI design time - in the mapping - to the stored procedure data type - we have specified 'DECIMAL' as the type for attribute of the import parameter of the stored procedure . My source field in the mapping is of type string.
    This is resulting in an error on the Adapter Engine - 'Cannot convert datetime to decimal'  ( as seen in RWB ) -
    Are we right in specifying DECIMAL as the type in the XI mapping to the type attribute of the stored procedure parameter ?
    Any pointers, thoughts shared on this is appreciated. Correct answers will be rewarded.

    Sai and Others
                         The problem was that - among the big number of stored procedure parameters - that were to be passed from XI to the stored procedure call - we had to disable a few of the fields inbetween - inorder to test the stored procedure call with the main parameters that were to be passed.
    This disabling of the selective fields inbetween - messed up the order inbetween the XI stored procedure datatype and the actual stored procedure definition. We learnt a lesson not to disable fields within a stored procedure - now the call to the stored procedure is going through without using any conversion function for the string to decimal - as long as a decimal value keeps appearing at the source field always ( which is the case here )
    Thanks for your pointers, thoughts and suggestions...

  • An intermittently terminating stored procedure

    If anyone has experience troubleshooting a stored procedure that intermittently terminates after partially progressing, please send things to check for.  Essentially, a .NET application invokes the stored procedure and waits for completion -- except
    the stored procedure appears to intermittently, abnormally terminate (judging by sp_who2 and intermediate event records inserted into a database table) and does not return an error to the application.  I am in the process of ruling out the .NET application
    as the cause.  I have recreated the issue with SQL Server 2008 R2 Standard and SQL Server 2012 R2 Standard.  I've reviewed the SQL Server Logs, doesn't appear to be any obviously related errors.  The stored procedure creates temp tables in tempdb,
    if that is relevant.  I've looked into adjusting SQL Server advanced parameter Query Wait, but this should have undesirable side effects unfortunately.  Do you recommend a SQL Server Profiler trace as a next troubleshooting step?

    I think a trace (Extended Events or Profiler) is a good next step in troubleshooting. If a T-SQL error occurs on the server side, it will bubble up to the .NET application as long as the connection is still there.  However, the error could be hidden
    behind result sets that are not consumed by the application.  Check the app code to ensure results are fully processed.
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • Call a pl/sql stored procedure from a report link

    Hello everyone:
    I have a report with a link in a column, which takes you to another page and passes values to that page, but also need the link, run a stored procedure before going to the other page.
    In the Forum I found cases similar to this, but none of the examples is clear to me how I do this. It seems that the target of the link should be URL, and also I have to call the stored procedure with a javascript function.
    My questions are:
    - Is this the best method to make what I need?
    - How should be the syntax of the link that takes me to another page and run the "stored procedure"
    - How and where I put the function "javascript" to run the "stored procedure"
    BDD: Oracle 11 g
    Apex version 4.1
    Best regards
    Gerard

    Hi,
    Change the link to call an apex.submit process. (javascript).
    Edit:
    I've set up a basic example.
    Region 1 (just so you can see the value getting set):
    select :P27_HIDDEN item_Value
    from dual
    Region 2:
    select rownum id, dbms_random.string('U', 12) sss
    from dual
    connect by level <= 20
    item attributes for ID:
    Target: URL
    URL: javascript:apex.submit({request:'NAVIGATE', set:{'P27_HIDDEN':#ID#}});
    (P27_HIDDEN is just a hidden item i created)
    http://apex.oracle.com/pls/apex/f?p=54920:27
    Edit2:
    In your case, then you can just have a page process based on conditions request = expression1, expression1: NAVIGATE..... then a page branch to go to the desired page, also with the same conditions
    Edit3:
    Im not sure what examples you are referring to , as you didn't supply any links; but you mention calling the stored procedure from javascript, so would likely involve some AJAX, but imo not necessary.

  • Calling a Oracle Stored Procedure which will take a while to complete

    Hey.
    I'm calling a Oracle stored procedure which goes of and do a whole lot of things and therefore takes a fair while to complete.
    Currently I am doing this:
    String sql = "begin concorde.start_transfer(); end;";
    HibernateUtil.getSessionFactory().openStatelessSession().connection().prepareCall(sql).execute();
    ....Where HibernateUtil is just a mean to get to the SessionFactory. The connection I get is the same one as a JDBC, I think.
    I would want to regain control of the application as soon as the procedure is called and continue with the rest of the logic.
    How do I do that? Do I have to initiate it from a different thread?
    Thanks

    If it was me I wouldn't have a stored proc that took a while to complete. Instead I would submit a job to job queue. In terms of implementation I would call a proc that writes a record to a table. Then a process in the database polls that table and runs jobs it finds there. Then reports results somewhere.
    Sometime later you collect the results.
    But without that then the solution in java is obvious - create a thread.

  • Opening a stored procedure in Crystal 12 with all formatting intact

    Is it possible to use Crystal to revise something in a stored procedure when the entire report was created via SQL?
    For clarity, I didn't create the procedure in question. I am trying to update some wording in a text box, but when I tried to pull up the stored procedure in Crystal, it brought  up a blank report with no formatting, no images, and no text boxes. I therefore assume that all of this non-field data has been coded into the stored procedure.
    Please assume for the purposes of this question that manually recreating the report from scratch is not an option. Also please assume that Crystal is the only tool I have available for updating the text box.
    In case it is relevant, I am using Crystal 12/2008, and the stored procedure is probably intended for Crystal 10 or 11. However, I am pretty sure it wouldn't matter which version it was intended for.

    Jane,
    1) All your stored procedure is going to do, at least as it pertains to CR (any version), is return a result set. It can do hundreds of things in the background, but for it to be of any use in CR it must simply provide a set of records... Nothing else.
    It will not hold any information pertaining to the report definition itself... No formatting... Nothing about manually placed text boxes...
    2) Stored Procedures aren't written for any specific report writing software. They are written for specific databases.
    That said, an SP can be written for the purpose of reporting in general in that it sole purpose in life is to supply a set of records when called upon to do so by whatever reporting software calls on it.
    3) You can't "Call up" an SP in CR. An SP is code that's stored on your database server. If you with to view the actual code that makes up the SP itself, throw "how to view the code in a stored procedure" into a Google search..
    HTH,
    Jason

  • Converting MS Sql server stored proc to Oracle stored procedure

    I need to convert this MS SQL Server 200 stored procedure to Oracle stored procedure. Any help great appreciated.
    Thank you,
    set nocount on
    declare @sp varchar(100)
    set @sp = '<< stored procedure name goes here >>'
    declare @oid int
    select @oid = o.id from sysobjects o where o.name = @sp
    declare @last int
    -- function signature
    select @last = max(c.colid)
    from dbo.syscolumns c
    where c.id = @oid
    select case c.colid
    when 1 then '[ SqlCommandMethod(CommandType.StoredProcedure) ]'
    + char(13) +
    'public static SqlCommand ' + @sp + '(' + char(13) +
    ' [ NonCommandParameter ] SqlConnection
    ' connection '
    + char(13) +
    else ''
    end
    + ' ' +
    case t.name
    when 'char' then
    '[ SqlParameter(' + convert(nvarchar(10), c.length) + ')  '
    when 'varchar' then
    '[ SqlParameter(' + convert(nvarchar(10), c.length) + ') ] '
    when 'nchar' then
    '[ SqlParameter(' + convert(nvarchar(10), c.length / 2) + ') ] '
    when 'nvarchar' then
    '[ SqlParameter(' + convert(nvarchar(10), c.length / 2) + ') ] '
    else ''
    end
    +
    case t.name
    when 'char' then 'string'
    when 'nchar' then 'string'
    when 'varchar' then 'string'
    when 'nvarchar' then 'string'
    when 'bit' then 'bool'
    when 'datetime' then 'DateTime'
    when 'float' then 'double'
    when 'real' then 'float'
    when 'int' then 'int'
    else 'object /* ' + t.name + ' */'
    end
    + ' ' + lower(substring(c.name, 2, 1)) + substring(c.name, 3, 100)
    +
    case c.colid
    when @last then ')' + char(13) + '{'
    else ','
    end
    from dbo.syscolumns c
    left outer join dbo.systypes t on c.xusertype = t.xusertype
    where c.id = @oid
    order by c.colid
    -- call to generator
    select case c.colid
    when 1 then
    ' return SqlCommandGenerator.GenerateCommand(connection,' +
    char(13)
    else ''
    end
    + ' ' + lower(substring(c.name, 2, 1)) + substring(c.name,
    3, 100)
    +
    case c.colid
    when @last then ');' + char(13) + '}'
    else ','
    end
    from dbo.syscolumns c
    where c.id = @oid
    order by c.colid

    It would have helped if you had posted your code.
    To create tables in procedures, you can use EXECUTE IMMEDIATE. For example, if within a procedure, you want to:
    CREATE TABLE table_name
    (column1 NUMBER,
    column2 VARCHAR2 (30),
    column3 DATE);
    Then, from within a procedure you can:
    CREATE OR REPLACE PROCEDURE procedure_name
    AS
    BEGIN
    EXECUTE IMMEDIATE 'CREATE TABLE table_name
    (column1 NUMBER,
    column2 VARCHAR2 (30),
    column3 DATE)';
    END procedure_name;
    EXEC procedure_name
    For the procedure to count the number of business days between two input dates, see the following link:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:91212348059

  • Need to insert data in 2 tables thro stored procedure

    I need to create a stored procedure which will insert data in two tables. The procedure will get
    its inputs from an Oracle Developer Form which will be inserted into the tables.
    The 2 tables structure:
    1.FEES_MASTER
    Name Null? Type
    FEES_ID NOT NULL NUMBER(8) -- Primary Key
    CS_ID NOT NULL NUMBER(8) -- Class Student ID; An enrolled student
    REC_DATE NOT NULL DATE -- Fees receipt date
    REC_AMOUNT NOT NULL NUMBER(6) -- Fees receipt amount
    2.FEES_DETAIL
    Name Null? Type
    FEES_ID NOT NULL NUMBER(8) -- Foreign Key
    MONTH NOT NULL DATE -- First of each month to identify fee month
    Scenario:
    A student submits fees for 3 months through Master/Detail related blocks in a Developer Form as
    Under:
    Fees Master
    Fees ID : 11002
    Class Student ID : 356
    Receipt Date : 06-JAN-2001
    Receipt Amount : 1500
    Fees Detail
    Fees ID Fees Month
    11002 01-JAN-2001
    11002 01-FEB-2001
    11002 01-MAR-2001
    I need to check each fees detail record for fees month duplication as well before inserting new records.
    How can this be achieved?
    Thanks in advance.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Fan Liu ([email protected]):
    create primary key in the detail table. i think it's FEES_ID + MONTH. then mark the columns in Forms as primary key property true, then call check_record_uniqueness built-in in on-check-unique trigger.<HR></BLOCKQUOTE>
    Thanks very much. But what I need is to ensure transaction integrity thro stored procedure. The system allows a certain CS_ID (i.e. Class Student ID, which is assigned a new one to every student annually) to submit fees for 12 months only, because a student stays in a class for a year. The 2 columns in the FEES_DETAIL table are composite primary key which only ensures that a certain FEES_ID will not be repeated for the same month. But suppose:
    1)this data already exist in the tables:
    Fees Master
    Fees ID : 11002
    Class Student ID : 356
    Receipt Date : 06-JAN-2001
    Receipt Amount : 1500
    Fees Detail
    Fees ID Fees Month
    11002 01-JAN-2001
    11002 01-FEB-2001
    11002 01-MAR-2001
    2)And this data is currently being inserted:
    Fees Master
    Fees ID : 11300
    Class Student ID : 356
    Receipt Date : 04-FEB-2001
    Receipt Amount : 1500
    Fees Detail
    Fees ID Fees Month
    11300 01-JAN-2001
    11300 01-FEB-2001
    11300 01-MAR-2001
    The data in the 2nd condition is perfectly valid but the application can't allow a student to submit fees for a month which he has already submitted. Now only a stored procedure can make sure after checking that the same student doesn't pay fees for duplicate months. Another reason for my emphasis on stored procedure is that what if a user tries to insert data thro an SQL* Plus session instead of the Form.
    PROBLEM: Now the problem I am having is I don't know how the procedure will take input for multiple records from the FEES_DETAIL block in the Form.
    Please assist in this regard. Thanks.

  • Do I have to add commit in SQL Server stored procedure

    In SQL Server, any statement not within a transaction is automatically commit. for example, single statement "INSERT INTO Table" is commit automatically. but in PL/SQL, you have to issue "COMMIT" after the statement. Since I have about 500 stored procedures need to be migrated from SQL Server to Oracle, Does any one has any solution for me, so I don't need to add "Commit" statement after every "Insert into Table" or "Update table" single statement.
    Thanks

    Jimmy,
    I can't think of any short cuts, only to at least commit at the end of each stored procedure as opposed to after each stmt.

  • How to trigger a Stored Procedure

    I have wriiten a Stored Procedure for Delivery Document which will update the SerialNumber defined as UDF in Item Row.
    But the problem is that the user has to exec the stored Procedure and have to give 2 parameters ie DocEntryNo, ItemCode.
    My requirement is that at the time of Saving the Delivery Document, the Stored Procedure should be triggered and it should automatically pick the DocEntryNo and ItemCode dynamically.
    At present the user has to run this Stored Procedure from Query Wizard after saving Delivery Document.
    exec setSerialNumber(1234,'ItemCode')
    The purpose is to display Serial Number after the ItemCode.

    Hi,
    set the parameters into variables and run sp.
    declare @par1 integer
    declare @par2 varchar(100)
    set @par1 = [$1.1.1.1.]
    set @par2 = [$1.1.1.1.]
    exec sp @par1, @par2

  • Is it possible to trigger an error so that the running stored procedure is stopped?

    Hello all,
    I want to run an existing stored procedure and then I want to manually trigger an error/abort/interruption so see what happens and do some testing with that.
    Is it possible to manually trigger an error/abort/interruption on a running stored procedure so that it is stopped?
    If yes, how can I do that?
    I hope someone has an idea. For me it sounds not really difficult, but I just do not get the idea how to do it.
    Kind regards
    Peter

    Hello Visakh,
    I dont want to modify the existing procedure. I just want to run it and than stop it, but not with the button to stop it, but "kill" it somehow with an error (with not destroying the database).
    Nope you cant simulate an intermediate failure inside procedure code from outside. For that you have to modify the actual sp code itself
    Another way is by doing data manipulation in such a way which causes a error in procedure but for that you need to revisit the logic to ensure you do changes in such way as to cause an error
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to stop logging in stored procedure?

    With interactive ISQL ssession, there is a command "stop logging" to stop ase logging for current session.
    How to do same thing for a stored procedure?

    No, each select/into will need to create a new table.
    With some planning/designing you could do something like:
    ==========================
    select ... into mytab1 ...
    select ... into mytab2 ... union all select * from mytab1
    --drop any indexes from mytab1
    truncate table mytab1
    drop table mytab1
    select ... into mytab3 ... union all select * from mytab2
    --drop any indexes from mytab2
    truncate table mytab2
    drop table mytab2
    ==========================
    Obviously you have to make the final decision ... minimize logging with more complicated coding *vs* accept logging overhead with less complicated coding.
    Just saw Kevin's response ... which is a more efficient method assuming each insert can stand on it's own.
    My example assumes some intermediate processing between the INSERTs (eg, insert mytab1, run some queries against mytab1, insert mytab2, run some queries against mytab2, insert mytab3) ... then again perhaps you could use the #temp tables for intermediate processing, too.
    There are a lot of ways to reduce your logging which ultimately depends on your exact requirements.

Maybe you are looking for

  • Have you fixed, in Firefox 5, the problem that existed in Firefox 4 with not being able to view PDF files?

    In Firefox 4 you had a bug that did not allow the viewing of PDF files. I see that you just released Firefox 5. Did Firefox 5 fix that problem?

  • How can i downgrade my ipod?

    I really dont like the new upgrade. I cant even download apps now. Cant even get in to app store And safari the same. I barely wrote this.

  • My music????

    I recieved an iPod Nano for Christmas. /Cheer Now I want to use all my music to make playlists on iTunes so I can misx and mach depending on what I want to hear. I have a very extensive collection of music which has all been converted to unprotected

  • Automatic Fax to vendors.

    Dear friends, Please note, in senario i have to around 2000 vendors and i want to fax them purchase orders automatically. Whick is the solution, Thanks to come back to me with a proposal using the standard SAP. Thanks in advance. Suri.

  • Balance Transfer from RG 23 A to RG 23 C

    Hello By mistake some of the balance that has to be uploaded to RG 23 C has been uploaded in RG 23 A while MIGO How can we correct the same, without reversing all the doc Regards Niti Narayan