Skip to content

Tag: oracle

This Oracle SQL SELECT shouldn’t work. Why does it?

I am debugging a query in Oracle 19c that is trying to sort a SELECT DISTINCT result by a field not in the query. (Note: This is the wrong way to do it. Do not do this.) This query is trying to return a unique list of customer names sorted with the most recent sale date first. It returns an

Show column according to parameter

I’m trying to write a SQL script that shows a column based on a user parameter. I can’t find an acceptable answer anywhere.  This is a simplified version of what I want to do (in OracleDB): The pseudo code of what I want could be This is the expected result: Answer You can just put the logic into the where

Is the Function in the GROUP BY Clause Necessary?

I’m an Oracle newbie just trying to learn. Are the following two queries equivalent in terms of their results? Query 1 Query 2: No TO_CHAR() in the GROUP BY Clause I’m using Oracle version 12.1. Answer Both queries won’t return the same result… unless customers.date includes only dates with no time part. The DATE type in Oracle includes the date

How to change my name into columns using sql

What is the best query to split name into columns? ie. if my name is VELOCITY in one column. How can i split it as Answer If you just have a single row then: Which outputs: CH V E L O C I T Y If you have multiple input rows then, from Oracle 12, you can use a LATERAL

Repeating JSON Aggregated Array with Row Limits

I have an Oracle 19 database with a JSON aggregated array which I need to cut off and repeat after a set number of rows, for example: …etc. Here’s some basic SQL to illustrate how my current dataset is put together: I need to push customer data to an API endpoint. Pushing 1 customer record at a time is not

How to fetch single records using case statements

I want to fetch single record from the table test_table if any one of the value is null in the column e_value then it should print No else Yes My Attempt: Current Output: Expected Output: Answer you can use GROUP BY and COUNT: The count will return number of non-null values db<>fiddle here

SQL missing parenthesis when creating a table [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 2 months ago. Improve this question I’m trying to create a table for a college project, but when I run my code it tells me I am missing