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
The Future of Agentic AI in Enterprise Compliance Automation
What if managing corporate compliance became as simple as giving an AI assistant a well-defined instruction? Imagine a finance director...
Scan From Webcam Online Without Installing an App
Need to scan from webcam without installing another app? A browser-based QR scanner makes the process simple. You only need...
What to Expect from a Global App Launch Agency
Coordinating a launch across a dozen countries at once sounds simple in a pitch deck. In practice, it's one of...
Parouzhomukiu2045: Future Quantum Tech & AI Innovations
Out here among flashing screens and tech talk, parouzhomukiu2045 shows up like a puzzle piece missing its box. It hits...
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...
