Subject Re: how to lpad in a stored procedure
Author Adam
Hi Dixon,

You can't use the syntax you are looking at.

Generators return a BigInt, not a varchar.
Lpad works on varchars, not integers / bigint / floats etc

You could write a custom UDF to do an int to varchar conversion, then
use LPAD, but judging from your code, this would be a really bad idea.

Why are you using a varchar(40) as your primary key?

You would be far better served using bigint. There is no way you
would be able to store enough rows to require every possible bigint,
I doubt there is a storage device in existance today which could
store that much info. Your model only seems to be concerned about
100,000,000 records. BigInt will work up to
18,446,744,073,709,551,616 records.

As Alan said, if it is simply a formatting question, then do this
from the client application.

Adam





--- In firebird-support@yahoogroups.com, "Dixon Epperson"
<dixonepperson@y...> wrote:
>
> I was browsing through the UDFs and saw a function I would like to
> use, but don't know how.
>
> example of use
>
> CREATE PROCEDURE NEWCUST(sCU_NAME VARCHAR(40))
> RETURNS (oID CHAR(8)) AS
> BEGIN
> oID = GEN_ID(GEN_CU_ID, 1);
>
> INSERT INTO CUSTINFO(CU_ID, CU_NAME) VALUES (:oID, :sCU_NAME);
>
> END;
>
> Now assuming the generator was started at 1,
> how would I get oID set to 00000001
>
> Add this line below the Gen_ID line?
> oID = lpad(oID, 8, '0');
>
> Will that work ok in a stored Procedure and is there anything I need
> to do to free the resources?
>
> E. D. Epperson