pub struct IntervalYM { /* private fields */ }
Expand description
Oracle-specific Interval Year to Month data type.
§Examples
// Create an interval by new().
let intvl1 = IntervalYM::new(2, 3)?;
// All arguments must be zero or negative to create a negative interval.
let intvl2 = IntervalYM::new(-2, -3)?;
// Convert to string.
assert_eq!(intvl1.to_string(), "+000000002-03");
assert_eq!(intvl2.to_string(), "-000000002-03");
// Create an interval with precision.
let intvl3 = IntervalYM::new(2, 3)?.and_prec(3)?;
// The string representation depends on the precisions.
assert_eq!(intvl3.to_string(), "+002-03");
// Precisions are ignored when intervals are compared.
assert!(intvl1 == intvl3);
// Create an interval from string.
let intvl4: IntervalYM = "+002-3".parse()?;
// The precision is determined by number of decimal digits in the string.
assert_eq!(intvl4.precision(), 3);
Fetch and bind interval values.
let conn = Connection::connect("scott", "tiger", "")?;
// Fetch IntervalYM
let sql = "select interval '+02-03' year to month from dual";
let intvl = conn.query_row_as::<IntervalYM>(sql, &[])?;
assert_eq!(intvl.to_string(), "+02-03");
// Bind IntervalYM
let sql = "begin \
:outval := to_timestamp('2017-08-09', 'yyyy-mm-dd') + :inval; \
end;";
let mut stmt = conn.statement(sql).build()?;
stmt.execute(&[&OracleType::Date, // bind null as date
&intvl, // bind the intvl variable
])?;
let outval: Timestamp = stmt.bind_value(1)?; // get the first bind value.
// 2017-08-09 + (2 years and 3 months)
assert_eq!(outval.to_string(), "2019-11-09 00:00:00");
Implementations§
Source§impl IntervalYM
impl IntervalYM
Sourcepub fn new(years: i32, months: i32) -> Result<IntervalYM>
pub fn new(years: i32, months: i32) -> Result<IntervalYM>
Creates a new IntervalYM.
Valid values are:
argument | valid values |
---|---|
years | -999999999 to 999999999 |
months | -11 to 11 |
All arguments must be zero or positive to create a positive interval. All arguments must be zero or negative to create a negative interval.
Sourcepub fn and_prec(&self, precision: u8) -> Result<IntervalYM>
pub fn and_prec(&self, precision: u8) -> Result<IntervalYM>
Creates a new IntervalYM with precision.
The precision affects text representation of IntervalYM. It doesn’t affect comparison.
Trait Implementations§
Source§impl Clone for IntervalYM
impl Clone for IntervalYM
Source§fn clone(&self) -> IntervalYM
fn clone(&self) -> IntervalYM
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for IntervalYM
impl Debug for IntervalYM
Source§impl Display for IntervalYM
impl Display for IntervalYM
Source§impl FromSql for IntervalYM
impl FromSql for IntervalYM
Source§impl FromStr for IntervalYM
impl FromStr for IntervalYM
Source§impl PartialEq for IntervalYM
impl PartialEq for IntervalYM
Source§impl ToSql for IntervalYM
impl ToSql for IntervalYM
Source§impl ToSqlNull for IntervalYM
impl ToSqlNull for IntervalYM
fn oratype_for_null(_conn: &Connection) -> Result<OracleType>
impl Copy for IntervalYM
Auto Trait Implementations§
impl Freeze for IntervalYM
impl RefUnwindSafe for IntervalYM
impl Send for IntervalYM
impl Sync for IntervalYM
impl Unpin for IntervalYM
impl UnwindSafe for IntervalYM
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more