Length Function

21 kali dilihat
Langsung ke pesan pertama yang belum dibaca

Dushyant Bhatia

belum dibaca,
15 Jan 2021, 05.49.5515/01/21
kepadaBetter Oracle functions support
Hello

I can see that the length funtion works only for character data type. How can I make it work for any other data type.?

Please advise.

Dushyant

Pavel Stehule

belum dibaca,
15 Jan 2021, 06.08.4715/01/21
kepadaorafce-...@googlegroups.com
Hi

pá 15. 1. 2021 v 11:49 odesílatel Dushyant Bhatia <dushy...@gmail.com> napsal:
Hello

I can see that the length funtion works only for character data type. How can I make it work for any other data type.?

Your query is too generic. Can you send an example, what you want?

Regards

Pavel

Please advise.

Dushyant

--
You received this message because you are subscribed to the Google Groups "Better Oracle functions support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orafce-genera...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/orafce-general/01da16e9-5abc-499e-8cbd-ea29a49ec3d2n%40googlegroups.com.

Dushyant Bhatia

belum dibaca,
15 Jan 2021, 07.39.2715/01/21
kepadaBetter Oracle functions support
Hey Pavel

Thanks for your quick response. The issue is something like this. 

If I execute

select length ('1') from dual;

It returns to me the correct value

but if i try to execute 

select length (1) from dual;

it throws an error.

Please let me know if you need more information

Thanks & Regards
Dushyant

Pavel Stehule

belum dibaca,
15 Jan 2021, 09.08.1915/01/21
kepadaorafce-...@googlegroups.com


pá 15. 1. 2021 v 13:39 odesílatel Dushyant Bhatia <dushy...@gmail.com> napsal:
Hey Pavel

Thanks for your quick response. The issue is something like this. 

If I execute

select length ('1') from dual;

It returns to me the correct value

but if i try to execute 

select length (1) from dual;

it throws an error.

Please let me know if you need more information

length is Postgres function, and it exists only for text types. Oracle is not type strict, and allows almost all possible conversions implicitly. Postgres is working differently.

you need to explicitly cast to text. This is preferred way

postgres=# select length(10::text);
┌────────┐
│ length │
╞════════╡
│      2 │
└────────┘
(1 row)

or you can write own SQL function

CREATE OR REPLACE FUNCTION length(anyelement)
RETURNS text AS $$
  SELECT length($1::text)
$$ LANGUAGE sql;

postgres=# select length(10);
┌────────┐
│ length │
╞════════╡
│ 2      │
└────────┘
(1 row)

Regards

Pavel





Thanks & Regards
Dushyant

On Friday, 15 January 2021 at 16:38:47 UTC+5:30 Pavel Stehule wrote:
Hi

pá 15. 1. 2021 v 11:49 odesílatel Dushyant Bhatia <dushy...@gmail.com> napsal:
Hello

I can see that the length funtion works only for character data type. How can I make it work for any other data type.?

Your query is too generic. Can you send an example, what you want?

Regards

Pavel

Please advise.

Dushyant

--
You received this message because you are subscribed to the Google Groups "Better Oracle functions support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orafce-genera...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/orafce-general/01da16e9-5abc-499e-8cbd-ea29a49ec3d2n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Better Oracle functions support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orafce-genera...@googlegroups.com.

Dushyant Bhatia

belum dibaca,
16 Jan 2021, 00.46.1916/01/21
kepadaBetter Oracle functions support
Thanks for this. I have a similar question on Decode. Will create a new thread for that.
Balas ke semua
Balas ke penulis
Teruskan
0 pesan baru