How can i order the results in my select query to have them like this? I tried this query but the result is not what I’m looking for: In which col1 represents the first number, col2 is the second one and col3 is the last number in the above example. This query returns: Thanks Answer Sort should be 1-3-2…
Tag: oracle
Select from one table if present,else select from another having latest date
There are Three tables T1 and T2 and T3 T3 stores person details T1 stores primary phone number of person, T2 stores non primary phone number of persons. T1 Personid Primaryphone dateload 1 1001 02/08/21 2 1002 03/07/21 4 1004 04/08/20 5 1005 08/09/20 T2 Personid NonPrimphone dateload 1 1011 12/03/21 3 1003 2…
Why did the ‘NOT IN’ work but not the ‘NOT EXISTS’?
I’ve been trying to improve my SQL and was playing around with a ‘NOT EXISTS’ function. I needed to find the names of salespeople who did not have any sales to company ‘RED’. I tried this and it did not work: This query ran but returned a NULL. Then I changed it to this and it wo…
Python: cx_Oracle does not like how I am entering date
I am trying to do a simple select all query in python using the Cx_oracle module. When I do a select all for the first ten rows in a table I am able to print our the output. However when I do a select all for the first ten rows for a specific date in the table all that gets
how to get the 1st day of the year sql query oracle
I need a sql query to get a 1st day of the 1st month of the year which i am passing. ex: If i am passing 2021, my output should be 01-JAN-2021 If i am passing 2020, my output should be 01-JAN-2020 Answer Assuming you are passing the year as the bind variable :year then: or
Remove duplicates with least row ids from Oracle
I have a database table which looks like ID Book_no Book_name Book_category ID1 1 B1 CB1 ID1 2 B1 CB1 ID1 3 B2 CB1 ID1 4 B2 CB1 ID1 5 B3 CB1 ID2 1 B1 CB2 ID2 2 B1 CB2 ID2 3 B2 CB2 And the expected result is like ID Book_No Book_name Book_category ID1 2 B1 CB1 ID1 4
Generate a range of records depending on from-to dates
I have a table of records like this: Item From To A 2018-01-03 2018-03-16 B 2021-05-25 2021-11-10 The output of select should look like: Item Month Year A 01 2018 A 02 2018 A 03 2018 B 05 2021 B 06 2021 B 07 2021 B 08 2021 Also the range should not exceed the current month. In example above
Oracle save updated rows in log
I have an update in my stored procedure. I would like to, save in my log the number of rows updated. How can I achieve this? Answer You can do something like this:
How to get old variable value from PL/SQL for loop?
I am trying to get old value from variable in PL/SQL for loop. For instance: I have l_sequnce variable with increment of 10. I hope I described the problem well 🙂 Answer Use ORDER BY in the SELECT statement and then you only need to check if the value has changed between the previous and current values: Or, d…
In Oracle SQL, replace variable number of placeholders with values from a second table
Table 1 has error messages with a variable number of numbered placeholders within squiggly brackets. I need to build the completed messsage with values from a 2nd table. Table 1: Table 2 The relationship between the tables is, of course, the error_id and placeholder/arg_seq_nbr values. A correct result would …