Subject Re: how to lpad in a stored procedure
Author Dixon Epperson
--- In firebird-support@yahoogroups.com, "Adam" <s3057043@y...> wrote:

It was just an example,<G> I'm not using a varchar as a primary key,
and as a practical matter, the 8 character digit will never be maxed
out. There just aren't that many of what we are looking at.

And even if there were, I am having to constrain this to another
database have to work with but didn't write.

I'm using a sequential generator because its an easy way to get a
sequential type number. I am using Char(8) because of external concerns.

I don't need to left pad, but would like to left pad because at
anygiven time, a file may be named that uses this left padded value.
So thats why I am doing it, or at least wanting to do it.

But point well taken on the generator returning a bigint.
there is another column I need to fix.
Thanx

E. D. Epperson


>
> 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