Hi,
something to set your teeth into
I know my way around in SQL but i need to convert this into PL/SQL and that's a little bit rusty
I have a form with a certain ID field.
The ID field is build like ABCD1234 (prefix + sequence)
The user selects the Char field from a lookup table. The length is 3 or 4 characters.
The number is supposed to be a sequence.
I want to select the last number that starts with that prefix and increase the sequence with 1.
I've gathered the following SQL statements that i would need. The 'DOCU%' part is supposed to be a variable (selected from screen).
----------------------------------SQL Statements ------------------------------
Get highest ITEM_ID
------------------------
select max(item_id)
from items
where item_id like 'DOCU%'
--> 'DOCU0006'
Length of String
-------------------
select length('DOCU0006') from dual
--> 8
Get Substring and extract sequence
-----------------------------------------
select substr('DOCU0006', 5) from dual ( (8-4) + 1 )
--> '0006'
String to Number and increase with 1
---------------------------------------------
select to_number('0006') +1 from dual
Convert number back to string
-----------------------------------
Select to_char(7,'0999') from dual
---> '0007'
----------------------------------SQL Statements ------------------------------
I would than add the '0007' to the prefix and write that as the ITEM_ID to the database.
Anyone got a suggestion on how to to this in PL/SQL ?
Regards,
Njitter