Skip to content

Tag: oracle

Replace characters with padding zeros

I have a table with values: and I need to replace the first dash (-) with zeros, so that the total length is exactly 18 characters, and insert it back into the database: If that is not possible, then maybe do the same using grep Answer I need to replace the first dash (-) with zeros, so that the total

Select from group by based on case statement

Based on a table like this I want to group by PRODID, then select a row based on a case statement. Case statement being if IND1 = 1 select row, else if IND2 = 1 select row, else select row with max DATE. If multiple indicators within a group are 1 select row with the max date from the group

Case statement based on the time

I have the following table Based on the transaction_DT: if the transaction between 04:00:00 PM to 08:00:00 AM + next day get “After Hour” Between 08:00:00 AM to 04:00:00 PM within same day get “Working Hour” Using the case statement it is not works! Answer Hmmm . . . how about somethin…

Why this select selects no rows

I am trying to select a highest earner in ‘IT’ department, but I keep selecting no rows. Salary and names are in table called employees while department_name is in a table named departments. Can anyone please explain why does this select no rows and how should I do it? Answer Why this select selec…

Oracle SQL regexp_substr number extraction behavior

In a sense I’ve answered my own question, but I’m trying to understand the answer better: When using regexp_substr (in oracle) to extract the first occurrence of a number (either single or multi digits), how/why do the modifiers * and + impact the results? Why does + provide the behavior I’m…