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 8158921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:45:45+00:00 2026-06-06T17:45:45+00:00

In the SQL Server, I can define local variables like this. declare @id number

  • 0

In the SQL Server, I can define local variables like this.

declare @id number := 1000

select * from tbl_A where id = @id;
select * from tbl_B where id = @id;

It is very convenient.
I tried to do same thing in PL/SQL but it doesn’t work.

DECLARE id number;
select 1000 into id from dual;

Do you know how to do something similar? The simplest method is my objective.

  • 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-06T17:45:46+00:00Added an answer on June 6, 2026 at 5:45 pm

    If you want to define a local variable in PL/SQL, you need a complete PL/SQL block

    DECLARE
      id NUMBER;
    BEGIN
      SELECT 1000
        INTO id
        FROM dual;
    END;
    

    or just

    DECLARE
      id NUMBER := 1000;
    BEGIN
      <<do something that uses the local variable>>
    END;
    

    If you want to declare a variable in SQL*Plus

    SQL> variable id number
    SQL> begin
           select 1000 into :id from dual;
         end;
         /
    
    SQL> print id
    
            ID
    ----------
          1000
    
    SQL> SELECT * FROM tbl_a WHERE id = :id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In MS SQL server, can i use a SELECT statement to define a CHECK
What is user define function in sql server 2005.How Can I see them from
In Oracle / SQL Server I can use the WITH keyword to define a
In SQL server I can say: Select top 50 percent How can I say
Possible Duplicate: Selecting data from two different servers in SQL Server How can I
In Oracle's PL-SQL, you can declare a variable and define its type based on
I have to work with multiple SQL Server tables that generally look like this:
In SQL Server 2008, we can define a table type and use it as
for SQL Server 2008 R2 I have a resultset that looks like this (note
I want to delete all rows from a SQL Server 2005 database. Can anyone

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.