module Sequel::Oracle::DatasetMethods

  1. lib/sequel/adapters/shared/oracle.rb

Included modules

  1. AutoCastDateAndTime

Constants

BITAND_PROC = lambda{|a, b| Sequel.lit(["CAST(BITAND(", ", ", ") AS INTEGER)"], a, b)}  
ROW_NUMBER_EXPRESSION = LiteralString.new('ROWNUM').freeze  

Public Instance methods

complex_expression_sql_append(sql, op, args)
[show source]
    # File lib/sequel/adapters/shared/oracle.rb
339 def complex_expression_sql_append(sql, op, args)
340   case op
341   when :&
342     complex_expression_arg_pairs_append(sql, args, &BITAND_PROC)
343   when :|
344     complex_expression_arg_pairs_append(sql, args){|a, b| Sequel.lit(["(", " - ", " + ", ")"], a, complex_expression_arg_pairs([a, b], &BITAND_PROC), b)}
345   when :^
346     complex_expression_arg_pairs_append(sql, args) do |*x|
347       s1 = complex_expression_arg_pairs(x){|a, b| Sequel.lit(["(", " - ", " + ", ")"], a, complex_expression_arg_pairs([a, b], &BITAND_PROC), b)}
348       s2 = complex_expression_arg_pairs(x, &BITAND_PROC)
349       Sequel.lit(["(", " - ", ")"], s1, s2)
350     end
351   when :~, :'!~', :'~*', :'!~*'
352     raise InvalidOperation, "Pattern matching via regular expressions is not supported in this Oracle version" unless supports_regexp?
353     if op == :'!~' || op == :'!~*'
354       sql << 'NOT '
355     end
356     sql << 'REGEXP_LIKE('
357     literal_append(sql, args[0])
358     sql << ','
359     literal_append(sql, args[1])
360     if op == :'~*' || op == :'!~*'
361       sql << ", 'i'"
362     end
363     sql << ')'
364   when :%, :<<, :>>, :'B~'
365     complex_expression_emulate_append(sql, op, args)
366   else
367     super
368   end
369 end
constant_sql_append(sql, c)

Oracle doesn’t support CURRENT_TIME, as it doesn’t have a type for storing just time values without a date, so use CURRENT_TIMESTAMP in its place.

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
374 def constant_sql_append(sql, c)
375   if c == :CURRENT_TIME
376     super(sql, :CURRENT_TIMESTAMP)
377   else
378     super
379   end
380 end
empty?()

Use a custom expression with EXISTS to determine whether a dataset is empty.

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
390 def empty?
391   if @opts[:sql]
392     naked.each{return false}
393     true
394   else
395     db[:dual].where(@opts[:offset] ? exists : unordered.exists).get(1) == nil
396   end
397 end
except(dataset, opts=OPTS)

Oracle uses MINUS instead of EXCEPT, and doesn’t support EXCEPT ALL

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
383 def except(dataset, opts=OPTS)
384   raise(Sequel::Error, "EXCEPT ALL not supported") if opts[:all]
385   compound_clone(:minus, dataset, opts)
386 end
recursive_cte_requires_column_aliases?()

Oracle requires recursive CTEs to have column aliases.

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
447 def recursive_cte_requires_column_aliases?
448   true
449 end
requires_sql_standard_datetimes?()

Oracle requires SQL standard datetimes

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
400 def requires_sql_standard_datetimes?
401   true
402 end
select_sql()

Handle LIMIT by using a unlimited subselect filtered with ROWNUM, unless Oracle 12 is used.

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
413 def select_sql
414   return super if @opts[:sql]
415   return super if supports_fetch_next_rows?
416 
417   o = @opts[:offset]
418   if o && o != 0
419     columns = clone(:append_sql=>String.new, :placeholder_literal_null=>true).columns
420     dsa1 = dataset_alias(1)
421     rn = row_number_column
422     limit = @opts[:limit]
423     ds = unlimited.
424       from_self(:alias=>dsa1).
425       select_append(ROW_NUMBER_EXPRESSION.as(rn)).
426       from_self(:alias=>dsa1).
427       select(*columns).
428       where(SQL::Identifier.new(rn) > o)
429     ds = ds.where(SQL::Identifier.new(rn) <= Sequel.+(o, limit)) if limit
430     sql = @opts[:append_sql] || String.new
431     subselect_sql_append(sql, ds)
432     sql
433   elsif limit = @opts[:limit]
434     ds = unlimited
435     # Lock doesn't work in subselects, so don't use a subselect when locking.
436     # Don't use a subselect if custom SQL is used, as it breaks somethings.
437     ds = ds.from_self unless @opts[:lock]
438     sql = @opts[:append_sql] || String.new
439     subselect_sql_append(sql, ds.where(SQL::ComplexExpression.new(:<=, ROW_NUMBER_EXPRESSION, limit)))
440     sql
441   else
442     super
443   end
444 end
sequence(s)

Create a copy of this dataset associated to the given sequence name, which will be used when calling insert to find the most recently inserted value for the sequence.

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
407 def sequence(s)
408   clone(:sequence=>s)
409 end
server_version()

The version of the database server

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
537 def server_version
538   db.server_version(@opts[:server])
539 end
supports_cte?(type=:select)
[show source]
    # File lib/sequel/adapters/shared/oracle.rb
451 def supports_cte?(type=:select)
452   type == :select
453 end
supports_derived_column_lists?()

Oracle does not support derived column lists

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
456 def supports_derived_column_lists?
457   false
458 end
supports_fetch_next_rows?()

Oracle supports FETCH NEXT ROWS since 12c, but it doesn’t work when locking or when skipping locked rows.

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
462 def supports_fetch_next_rows?
463   server_version >= 12000000 && !(@opts[:lock] || @opts[:skip_locked])
464 end
supports_group_cube?()

Oracle supports GROUP BY CUBE

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
467 def supports_group_cube?
468   true
469 end
supports_group_rollup?()

Oracle supports GROUP BY ROLLUP

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
472 def supports_group_rollup?
473   true
474 end
supports_grouping_sets?()

Oracle supports GROUPING SETS

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
477 def supports_grouping_sets?
478   true
479 end
supports_intersect_except_all?()

Oracle does not support INTERSECT ALL or EXCEPT ALL

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
482 def supports_intersect_except_all?
483   false
484 end
supports_is_true?()

Oracle does not support IS TRUE.

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
487 def supports_is_true?
488   false
489 end
supports_limits_in_correlated_subqueries?()

Oracle does not support limits in correlated subqueries.

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
492 def supports_limits_in_correlated_subqueries?
493   false
494 end
supports_merge?()

Oracle supports MERGE

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
497 def supports_merge?
498   true
499 end
supports_nowait?()

Oracle supports NOWAIT.

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
502 def supports_nowait?
503   true
504 end
supports_offsets_in_correlated_subqueries?()

Oracle does not support offsets in correlated subqueries.

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
507 def supports_offsets_in_correlated_subqueries?
508   false
509 end
supports_regexp?()

Oracle 10+ supports pattern matching via regular expressions

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
542 def supports_regexp?
543   server_version >= 10010002
544 end
supports_select_all_and_column?()

Oracle does not support SELECT *, column

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
512 def supports_select_all_and_column?
513   false
514 end
supports_skip_locked?()

Oracle supports SKIP LOCKED.

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
517 def supports_skip_locked?
518   true
519 end
supports_timestamp_timezones?()

Oracle supports timezones in literal timestamps.

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
522 def supports_timestamp_timezones?
523   true
524 end
supports_where_true?()

Oracle does not support WHERE ‘Y’ for WHERE TRUE.

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
527 def supports_where_true?
528   false
529 end
supports_window_functions?()

Oracle supports window functions

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
532 def supports_window_functions?
533   true
534 end