Skip to content

Tag: oracle

Oracle: When are constraints checked?

In my understanding constraints should generally be checked at the end of a transaction. So, in a simple example where we have one table A with the only column P, which is its primary key, and a table B with the primary key P and the foreign key F on A.P, the following should work (on empty tables): However, …

Oracle SQL Extract Year from VARCHAR2

Please don’t roast me for not being able to figure this out. I’m a beginner with SQL and I’ve been trying to find a solution and make it work for at least a couple hours in total. I know the date fields should be stored as dates, not varchar2, but I have no control over that. I feel like I&#…

Oracle SQL – Assign number to distinct tech_spec

In Oracle SQL, I’m trying to assign a unique number to each distinct tech_spec. Output: I’m trying to get assign each distinct tech_spec a number. I have been searching for a way to do this but can’t come up with anything. Output desired: Thanks in advance. Answer Use dense_rank(): You shoul…

Select row of data to be the output header

I have a very large set of data that is formed similar to this: I want to produce report output that drops the table headers (field1, field2, field3) and instead use data row1 as headers in output. I am able to do this nicely in SQLPlus and SPOOL to CSV, but I want to do everything in PLSQL so that