Creato da pastuweb.com
Share My Page
My Social Accounts
Account FaceBook Account LinkedIn Account Twitter Account Google Plus Account Git Hub
CREATE OR REPLACE FUNCTION <user>.NEXTID
Return Varchar2 is
   Valore       Number;
   Resto        Binary_Integer;
   Base         Number(3);
   HashKey      Varchar2(15);
   TYPE Cifre IS TABLE OF CHAR(1);
   Chset Cifre := Cifre('0','1','2','3','4','5','6','7','8','9','A','B','C',
'D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
Begin
---
   Select WH_SEQUENCE.NEXTVAL
     Into Valore
     From DUAL;
---
   Base := Chset.Count ;
   Resto := Mod (Valore,Base) ;
   Valore := Trunc(Valore/Base);
   HashKey := Chset(Resto+1);
   While ( Valore > 0 )
   loop
      Resto := Mod (Valore,Base);
      Valore := Trunc(Valore/Base);
      HashKey := Concat(Chset(Resto+1),HashKey);
   end loop;
   Return (Lpad(HashKey,6,'0'));
Exception
   When OTHERS Then
      dbms_output.put_line (Sqlerrm);
      Return (Lpad(HashKey,6,'#'));
End NEXTID;
/
 
After you create that function, you can use its in this mode:
 
For example in Java / JDBC:
String queryStr= "select NEXTID from dual";
Query query = getSession().createSQLQuery(queryStr);
new_id = query.list().get(0).toString();
 
 
 
Average (1 Vote)
The average rating is 5.0 stars out of 5.