Solved

How to create a unique ID for one process?

Posted on 2013-01-19
7
353 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 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 76

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

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…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now