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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:35:24+00:00 2026-05-15T14:35:24+00:00

When i ran the below queries it’s failing in the second query becuase prev_test_ref1

  • 0

When i ran the below queries it’s failing in the second query becuase prev_test_ref1 variable is not defined. If i remove the insert statement in the first query ,run again then it’s working and using the prev_test_ref1 value from the first sql query in second query. Is it because of variable scope? How can i resolve this with the insert statement.

QUERY1

column prev_test_ref1 new_value prev_test_ref1  ;

insert into testing.test_ref_details(TEST_TYPE,TEST_REF_NO)
select  '1',max(test_ref_no) as prev_test_ref1
from    testing.test_runs_status
where   test_type = 1
and run_status = 1
and test_end_dt = (select last_day(add_months(trunc(sysdate),-6))+2 from dual)
group by test_end_dt
;

QUERY2

column last_test_end_dt new_value last_test_end_dt;

select to_char(test_completion_dt,'DD-MON-YYYY HH24:MI:SS') as last_test_end_dt
from testing.test_runs_status
where test_ref_no = '&prev_test_ref1';
  • 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-15T14:35:25+00:00Added an answer on May 15, 2026 at 2:35 pm

    In SQLPlus substitution variables will only be defined with SELECT statements. Your first insert doesn’t return rows so it won’t work (think about it: it only returns 1 row inserted., SQLPlus has no way to know the value inserted.)

    I suggest you add a step to save the value into the variable (or use a PL/SQL block):

    column prev_test_ref1 new_value prev_test_ref1  ;
    
    SELECT MAX(test_ref_no) AS prev_test_ref1
      FROM testing.test_runs_status
     WHERE test_type = 1
       AND run_status = 1
       AND test_end_dt = (SELECT last_day(add_months(trunc(SYSDATE), -6)) + 2 
                            FROM dual)
     GROUP BY test_end_dt;
    
     INSERT INTO testing.test_ref_details(TEST_TYPE,TEST_REF_NO) 
        VALUES ('1', &prev_test_ref1);
    
     SELECT ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below when ran does not display the data, do you know what
I ran the following simple query that looks like the example below: (Briefly; one
I've just started with opengl but I ran into some strange behaviour. Below I
I ran into the problem that my primary key sequence is not in sync
I ran into an interesting error with the following LiNQ query using LiNQPad and
I ran the below script to set environment variables for oracle(oracle_env.sh which comes with
I ran the code below expecting flow to be locked on the 2nd time
I ran truss command on executable and get the below output: stat64(/net/xyzmachine/vol/tools/solx64/studio11/SUNWspro/lib/rw7/librt.so.1, 0x080474A0) (sleeping...)
Hi i'm trying to process the mysql_fetch_array query below and simplify the code so
I have a joinable pthread runner function defined as below: void *sumOfProducts(void *param) {

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.