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

  • SEARCH
  • Home
  • 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 8041267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:09:22+00:00 2026-06-05T04:09:22+00:00

Can someone help me understand why I can declare a hardcoded date value in

  • 0

Can someone help me understand why I can declare a hardcoded date value in a package but not assign the value from a query? I’ve seen a number of examples (including the reference book) that show declarations of hardcoded values but I’m unable to locate examples of assigning values to variable through queries.

This is allowed:

create or replace package body PACKAGE_NAME AS
    tDate DATE := '2012-05-30';
    -- ...procedures follow

This is allowed:

create or replace package body PACKAGE_NAME AS
    tDate DATE := sysdate;

This is not allowed:

create or replace package body PACKAGE_NAME AS
    tDate DATE := select MAX(date_) from Table_Name;

I’ve tried a number of ways and I’m ok with it not working – I can use it as needed in the procedures themselves. But I’d like to know why I can’t assign a value to tDate this way? The specific error is:

Encountered the symbol ‘SELECT’ when expecting ….

Adding that I can get variable values assigned through queries in a stored procedure but the same process does not seem to work for package body.

PROCEDURE Proc_Name IS
tDate Date;
BEGIN
SELECT MAX(date_) into tDate from Table_Name;
  • 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-06-05T04:09:24+00:00Added an answer on June 5, 2026 at 4:09 am

    You need to create a package initialization block in your package body. This is a relatively arcane bit of PL/SQL package lore, but it’s there and can be used. Here’s an example:

    CREATE OR REPLACE PACKAGE TEST_PKG IS
      tDate  DATE;
    END TEST_PKG;
    

    Here we’ve created a package spec which contains only a single DATE variable. Now we’ll create a simple body which initializes that variable using a SELECT statement:

    CREATE OR REPLACE PACKAGE BODY TEST_PKG IS
      -- package-private variables go first (if any)
    (...) 
      -- then the public functions/procedures
    (...)
      -- then a final BEGIN-END block which is the package initialization block
    BEGIN
      SELECT SYSDATE
        INTO tDATE
        FROM DUAL;
    EXCEPTION  -- you can have exception handlers in your initialization block
      WHEN OTHERS THEN
        NULL;  -- pointless here, but this is just an example
        RAISE;
    END TEST_PKG;
    

    Now if you execute the following:

    begin
      -- Test statements here
      DBMS_OUTPUT.PUT_LINE('TEST_PKG.tDate = ' || TEST_PKG.tDate);
    end;
    

    it should print the current date.

    Share and enjoy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can someone help me understand this because it's working in as3 but not so
Can someone help me understand what's wrong with this query: DELETE FROM noteproject INNER
Can someone help me understand why the following query is not offsetting correctly? It's
Can someone help me understand the scoping rules in Java? This is clearly not
Can someone help me understand how to convert this sql query to a named_scope
Can someone help me understand how to write this case statement properly its not
Can someone help me understand this line of jquery code?: $(this).find('input[type=submit]:not(.cancel), button').click(function () I'm
(Specifically, I'm using Backbone Model events) Can someone help me understand how javascript events
Can someone help me understand why this gives an output of 0? #include <iostream>
Can someone help me understand this topshelf project...mainly the difference between ConfigureServiceinIsolation and ConfigureService.

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.