Solved

How to create a unique ID for one process?

Posted on 2013-01-19
7
357 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 20

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 77

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

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 20

Accepted Solution

by:
flow01 earned 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

740 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