Select different query based on a variable
I want to execute a different query based on the value of a variable. I have a table with a lot of columns, and I want to select and rename a different numbers of fields based on a variable.
Something like
var varbl VARCHAR2
exec :varbl := 'XX'
if :varbl = 'XX'
(select a, b, c from table1 where cond)
elsif :varbl = 'XXXX'
(select d, e, f, g from table1 where cond)
end
I was trying to achieve this trough
decode( :varbl, 'XX',
(QUERY 1),
(decode( :varbl, 'XXX',
(QUERY 2), default)),
default)
but it doesn’t work, because decode should be used in a SELECT clause and i loose the name of the columns. furthermore, I get ‘too many values’ as error if I select more than a column in the inner queries.
I’m working on Oracle SQL.
This answer doesn’t work for me, because I have at least 30 fields to differentiate, in 3 different cases. I just want some solution that allows me to execute a different query.
More Stories
Diseño Web República Dominicana: Potenciando la Presencia Digital de Tu Negocio
En la era digital, tener una presencia en línea sólida ya no es opcional: es esencial para que cualquier negocio...
Web Design in the Dominican Republic: Crafting Digital Experiences That Convert
In today’s fast-paced digital world, having a strong online presence is no longer optional—it’s essential. For businesses in the Dominican...
How to Find the Perfect Software Development Partner for Your Web Development Needs
In the vast landscape of software development companies, finding the right partner for your web development projects can feel like...
Navigate the Future of Tech with Mariox Software: Top Mobile App Development in Dallas
Whether you're a pro entrepreneur with a groundbreaking concept or a small commercial enterprise proprietor looking to optimize your workflow,...
Rock 4 SE – Setting The Benchmark For Enterprise Operations
Each and every business today requires a computer in some form to make the work easy. It isn’t always a...
Enhancing Your Webshop with Magento: A Comprehensive Guide
The world of e-commerce has witnessed exponential growth over the years, and having a robust online presence is crucial for...
