Re: BIN()
От | Tino Wildenhain |
---|---|
Тема | Re: BIN() |
Дата | |
Msg-id | 1133332956.5734.34.camel@Andrea.peacock.de обсуждение исходный текст |
Ответ на | BIN() (Christopher Kings-Lynne <chriskl@familyhealth.com.au>) |
Ответы |
Re: BIN()
|
Список | pgsql-hackers |
Am Mittwoch, den 30.11.2005, 10:15 +0800 schrieb Christopher Kings-Lynne: > Hi guys, > > How would I go about implementing MySQL's BIN() function easily in PL/SQL. > > mysql> SELECT BIN(12); > -> '1100' > > Basically it converts a bigint to a string containing 1's and 0's. > > I've tried messing about with bit() types, but those types lack casts to > text, etc. And they are left padded with many zeros. In python, I usually go like this: def trans(value,base="01"): value,r=divmod(value,len(base)) if value: return trans(value,base)+base[r] return base[r] While base above has a default of "01" which let it render binary: trans(10) -> '1010' you can use any base you want: trans(10,"0123456789abcdef") -> 'a' and so on. If you want it easy, just put above code into a pl/python function. Or rewrite it in C or pl/pgsql or something.
В списке pgsql-hackers по дате отправления: