?
Solved

How to create a unique ID for one process?

Posted on 2013-01-19
7
Medium Priority
?
362 Views
Last Modified: 2013-02-04
I am using one table to store all logs.

the table is inserted through procedure, and I am calling the procedure in all places.

So, this will give me the flow, and will be able to analyze when there is some error.

Now, I want to use one unique number for one process.

Like I am doing one operation from front end, so I should have one unique  number to identify all the records that are coming through that process. So that I can query using that key.

How is this possible?
0
Comment
Question by:sakthikumar
7 Comments
 
LVL 21

Expert Comment

by:flow01
ID: 38796300
Create a sequence  

CREATE SEQUENCE process_id;
and use the   next_val of it at the start of each process

create or replace
procedure xprocess
is
  v_process_id pls_integer;
begin
   select process_id.nextval
   into v_process_id
  from dual;
  -- rest of your process  as an example :
  dbms_output.put_line('process_id:' || v_process_id);
end;
/

excuting for example in sqlplus

SQL> set serveroutput on
SQL> begin
  2    xprocess;
  3    xprocess;
  4  end;
  5  /
process_id:1
process_id:2
0
 
LVL 14

Expert Comment

by:ajexpert
ID: 38797008
In your log table, you can create one column, say CREATED_BY.

If you have limited and identifiable number of processes, I prefer to identify them with some some distinct numbers.

So
Process1      := 101
Process2      := 102

and so on...

I
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 38797205
I don't think a sequence will work here.

If you can change all the apps that call the procedure, then the unique process id will work.

This may or may not work but to keep app changes to a minimum, see if you can use sys_context inside the procedure to grab the client's info like ip address.

If you use an app server/web server then it probably won't work since it will return the ip address of the client which would be the app server or web server.

In this case, you will need to change the apps themselves to pass in some identifier.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 21

Expert Comment

by:flow01
ID: 38797309
I don't agree :   the process-id can be set in the initial-procedure the apps calls,

wether the apps needs the process-id depends on the way the application is designed.
If the aim is to follow the flow of 1 single call from the app on it's way to different procedures it's enough, unless the app can call either procedure A or procedure B and procedure A wil call also procedure B in it's flow.
The id can be passed as arguments with the procedure or saved at session level as a context variable,  a global temporary table , a package variable .
0
 

Author Comment

by:sakthikumar
ID: 38797675
I want transaction level logging, there is no clear starting point / ending point for my process.

like atleast there should be one sequeunce for all records that is before a commit /rollback.
0
 

Author Comment

by:sakthikumar
ID: 38797678
For ex: the below procedure call may not always be the starting point for the process.

crt_nomination(pi_port         => pi_port,
                   pi_terminal     => pi_terminal,
                   pi_hn_gen_code  => pi_hn_gen_code,
                   pi_hn_gen_type  => pi_hn_gen_type,
                   pi_hn_by_code   => pi_hn_by_code,
                   pi_hn_by_type   => pi_hn_by_type,
                   pi_hn_to_code   => pi_hn_to_code,
                   pi_hn_to_type   => pi_hn_to_type,
                   pi_boe_no       => pi_boe_no,
                   pi_do_no        => pi_do_no,
                   pi_arn_no       => pi_arn_no,
                   pi_arn_dtl_no   => pi_arn_dtl_no,
                   pi_user_id      => pi_user_id,
                   pi_contr_no     => pi_contr_no,
                   pi_crt_date     => pi_crt_date,
                   pi_mt_contr_cnt => pi_mt_contr_cnt,
                   pi_move_type    => pi_move_type,
                   pi_desig        => pi_desig,
                   pi_txn_src      => pi_txn_src,
                   pio_hn_id       => pio_hn_id,
                   po_err_code     => po_err_code,
                   po_err_msg      => po_err_msg);
0
 
LVL 21

Accepted Solution

by:
flow01 earned 2000 total points
ID: 38798031
If it's on transaction level

define a global_temporary table  tmp_process_id with  on column process-id

In the procedure for inserting the log-records (or on a trigger on the log-records:
get the process_id from tmp_process_id
   (there is always 0 or 1 record)
   if no data found insert a record with a new-process-id  using the sequence
      and use the process_id for identification of the transaction
   when there is a record use the process_id in it

committing or rollback wil empty the global_temporary table
so on the next log writing you wil get a new process_id

beware :  
1) if you log within a discrete transactions procedure they will be also get a new process_id

2) it works on commit/rollback  in the database :  commit/rollback in a form will only result in a database action if there was a change in the block-data of  the form
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows how to recover a database from a user managed backup
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question