Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3338208
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:20:52+00:00 2026-05-18T00:20:52+00:00

I have a table with a date column that I know is stored in

  • 0

I have a table with a date column that I know is stored in GMT. I have a procedure that accepts a date input and an account ID. The procedure:
1) gets the account ID timezone (stored in table account)
2) determines the start and end range in GMT as follows:
v_start_time := cast( from_tz( cast( i_date as timestamp ), v_tz ) at time zone c_gmt as date ); — where i_date is input, v_tz is ‘US/Eastern’ or any other tzname from v$timezone_names, and c_gmt is the string ‘GMT’
v_end_time := v_start_time + 1; — Add exactly one day to start date
3) return sys_refcursor to caller as:

open o_cur for
select gmt_col, some_value
from my_table
where account_id = i_account_id
    and gmt_col between v_start_time and v_end_time;

However, the developer would like both the gmt_date and the local time in the cursor. First, I attempted to use the exact same conversion method as I had to determine v_start_time, that is:

open o_cur for 
select gmt_col,
    cast( from_tz( cast( gmt_col as timestamp ), c_gmt ) at time zone v_tz as date ) as local_time, some_value
from my_table
where account_id = i_account_id
    and gmt_col between v_start_time and v_end_time;

However, when compiled, this results in ORA-00905: missing keyword. I attempted to add the single quotes around the “v_tz” like: chr( 39 ) || v_tz || chr( 39 ), but that doesn’t work – the proc compiles, but when I open the cursor, I get ORA-01882: timezone region not found. After a bit of experimentation, here are two solutions that allow “at time zone” to work smoothly in sql:

SOLUTION 1:

open o_cur for
select gmt_col,
    cast( from_tz( cast( gmt_col as timestamp ), c_gmt ) at time zone ( select v_tz from dual ) as date ) as local_time, some_value
from my_table
where account_id = i_account_id
    and gmt_col between v_start_time and v_end_time;

SOLUTION 2:

in package spec:

function echo( i_sound in varchar2 ) return varchar2;
pragma restrict_references( echo, wnps, rnps, wnds, rnds );

in package body:

function echo( i_sound in varchar2 ) return varchar2 is begin return i_sound; end;

in procedure:

open o_cur for
select gmt_col,
    cast( from_tz( cast( gmt_col as timestamp ), c_gmt ) at time zone echo( v_tz ) as date ) as local_time, some_value
from my_table
where account_id = i_account_id
   and gmt_col between v_start_time and v_end_time;

Performance appears to be comparable for each. The second solution hints at something I’ve started to do recently, which is to use functions to return “constants” with pragma restrict_references, so I can use the constant values flexibly between pl/sql and sql. For example:

function c_gmt return varchar2;
pragma restrict_references( c_gmt, wnds, rnds, wnps, rnps );

select * from v$timezone_names where tzabbrev = c_gmt;
select c_gmt from dual;
v_start_time := blah blah blah || c_gmt;
etc…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:20:53+00:00Added an answer on May 18, 2026 at 12:20 am

    You shouldn’t need the extra select from dual. Just putting the variable in parenthesis should do the trick (don’t ask me why though):

    open o_cur for  
    select gmt_col, 
        cast( from_tz( cast( gmt_col as timestamp ), c_gmt ) at time zone (v_tz) as date ) as local_time, some_value 
    from my_table 
    where account_id = i_account_id 
        and gmt_col between v_start_time and v_end_time; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have data stored in a mySQL table under the column type timestamp that
I have a table with a Date column. Each Date may appear multiple times.
I have a table with a Date column, and I would like to do
I have a date and time column in my mysql table called start_date and
Let's say that I want to have a table that logs the date and
I have a table with columns Index, Date where an Index may have multiple
I have a table of data sorted by date, from which a user can
I have a table that looks like that: The rows are sorted by CLNDR_DATE
I have a table of items, each of which has a date associated with
I have a set of records in my MS SQL table. With Date as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.