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
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...
9012/HIR2 LED Headlight Bulbs: Enhancing the Look of Your Vehicle
9012/HIR2 LED Headlight Bulbs are a popular choice for upgrading the look of a vehicle. These bulbs, also known as...
8 Do’s And Don’ts For Integrating Animation With Web Design
Whether you are designing for a client or just for yourself, integrating animation into your designs does have its advantages....