Skip to Main Content

Write a Get_bit Function

user8101600Oct 29 2014 — edited Oct 31 2014

Hi,

I have a get_bit function in Postgres database.  In Oracle, there is no built-in function to handle the get_bit.    I need to write my custom Oracle PLSQL function to mimic this get_bit fucntion's behavior.  Can anyone have any suggestion on how to do that?   Thanks!

The definition of get_bit is as the following:

Function

Return Type

Description

Example

Result

get_bit(string,offset)

int

Extract bit from string

get_bit(E'Th\\000omas'::bytea, 45)

1

get_bit(string, offset)(returns int)
Extract bit from string
get_bit(E'Th\\000omas'::bytea, 45) => 1

Note that the bits within a byte are numbered with the least significant bit being the zero bit. In the above example, the 'a' is the

byte being referenced and it contains x'61' => 0110 0001 and the third bit from the left (bit 5 starting with zero on the right) is returned.

This post has been answered by odie_63 on Oct 29 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked due to inactivity on Nov 28 2014
Added on Oct 29 2014
19 comments
4,625 views