Class: OCI8::BindType::IntervalYM

Inherits:
OCIIntervalYM
  • Object
show all
Defined in:
lib/oci8/datetime.rb

Overview

– OCI8::BindType::IntervalYM ++

This is a helper class to bind ruby’s Integer object as Oracle’s INTERVAL YEAR TO MONTH datatype.

Select

The fetched value for a INTERVAL YEAR TO MONTH column is an Integer which means the months between two timestamps.

Bind

You cannot bind as INTERVAL YEAR TO MONTH implicitly. It must be bound explicitly with :interval_ym.

# output bind variable
cursor = conn.parse(<<-EOS)
  BEGIN
    :interval := (:ts1 - :ts2) YEAR TO MONTH;
  END;
EOS
cursor.bind_param(:interval, nil, :interval_ym)
cursor.bind_param(:ts1, DateTime.parse('1969-11-19 06:54:35 00:00'))
cursor.bind_param(:ts2, DateTime.parse('1969-07-20 20:17:40 00:00'))
cursor.exec
cursor[:interval] # => 4 (months)
cursor.close

# input bind variable
cursor = conn.parse(<<-EOS)
  BEGIN
    :ts1 := :ts2 + :interval;
  END;
EOS
cursor.bind_param(:ts1, nil, DateTime)
cursor.bind_param(:ts2, Date.parse('1969-11-19'))
cursor.bind_param(:interval, 4, :interval_ym)
cursor.exec
cursor[:ts1].strftime('%Y-%m-%d') # => 1970-03-19
cursor.close

Instance Method Summary collapse

Instance Method Details

#getObject

:nodoc:



390
391
392
393
394
395
# File 'lib/oci8/datetime.rb', line 390

def get() # :nodoc:
  val = super()
  return nil if val.nil?
  year, month = val
  year * 12 + month
end

#set(val) ⇒ Object

:nodoc:



384
385
386
387
388
389
# File 'lib/oci8/datetime.rb', line 384

def set(val) # :nodoc:
  unless val.nil?
    val = [val / 12, val % 12]
  end
  super(val)
end