Friday Philosophy – If Only I Was As Good a Programmer As I Thought I Was Aged 22 January 29, 2016
Posted by mwidlake in Friday Philosophy, humour, Perceptions, Programming, Uncategorized.Tags: Humour, perception, system development
6 comments
I saw a tweet that made me smile a few days ago:
Like many of you, I started out my working life in IT as a computer programmer. Like some of you, I still am a computer programmer from time to time. I don’t think I’ve had a year of my working life when I did not do either some application development programming or some database infrastructure programming. I am constantly writing small (or not so small) SQL or PL/SQL programs to do what I do in Oracle.
I started programming in school, I did an “O” level in computer studies (the exams we sat in the UK aged 16, up until 1988!), and I was pretty good at the programming as compared to my fellow class mates. My first “real” program played Noughts and Crosses (tic-tac-toe to our American cousins and maybe others) and version 2 was unbeatable. Which at the time I thought was pretty cool.
but Wikipedia now tells me is pretty easy :-). I also remember someone in the year above me unrolling some huge printout of the role-playing game he was writing (you know, the old textual “you have walked into a room where there is a lion, a bar of soap and a chandelier, what do you want to do?” sort of thing) and telling me I would never be able to do it. I just looked at the code and thought: Why have you hard-coded every decision and used all those GOTOs? Some sort of loop and a data block to look up question, answers and consequences would be much smaller and easy to extend? I don’t think he liked me voicing that opinion…
I did not do any programming of any consequence as part of my college course but after that I started work as a computer programmer (sorry “analyst programmer”) in the National Health Service. Again, I seemed better at it than most of those around me, fixing bugs that others had given up on and coding the tricky stuff no one else wanted to touch. And after a year or so, I was convinced I was a programming god!
I wasn’t of course. Part of it was my juvenile, naive ego and the other part was that, fundamentally, many of those around me were bad programmers. Anybody decent either did not join in the first place or got a better job elsewhere that paid more than the NHS did. I eventually did that myself and joined Oracle. Where I realised that (a) SQL confused the hell out of me and (b) when I started using PL/SQL there were plenty of people around me who were better at traditional programming than I.
I think it took me about a year to feel I was damned good at both of them. Guess what? I was wrong. I was simply competent. But after a year or two more I did two things that, for me, finally did make me into a good programmer:
- I went contracting so I worked in a lot of places, saw a lot more examples of good and bad code and I met a lot more programmers.
- I think I hit mental puberty and woke up to the fact that I needed to listen and learn more.
Since then, I think my own opinion of my coding skills has generally dropped year on year, even though I would like to think I continue to get better at actually constructing computer programs and suites of programs.
So yes, I wish I was as good a programmer now as I thought I was aged 22. And after 25 years at it (actually, pretty much 35 years at it on and off!) just like Rich Rogers (or is it John D Cook? I can’t quite decide if it is a quotation or not) I think I am finally getting moderately good at writing programs. If I continue to follow this trend, on my 65th birthday I will be convinced I can’t program for toffee and yet will finally be a Good Programmer.
I wonder if anyone would still employ me to do it by then?
ORA_ROWSCN – When Was My Record Commited January 25, 2016
Posted by mwidlake in SQL.Tags: SQL
1 comment so far
I was going to do a follow-up post to my post on USERENV(‘COMMITSCN’) just to describe the slightly better known but still overlooked (and possibly more useful) ORA_ROWSCN – but I don’t need to!
As Neil Chandler has done this excellent post on it
Go and look at that post, it has all the information and detail you were actually looking for.
However, for any of you search-engine-seekers who can’t face the pain of following a link {it’s such a hard life for the modern knowledge-by-mouse-click generation}, here are the bare bones:
ORA_ROWSCN is a pseudo column that, by default, shows you the SCN (System Change Number) when the block was last changed. You can create a table with the ROWDEPENDENCIES extension to track it for individual rows but you can’t alter a table to add it. So usually you see a (conservative) last-change-scn for the block. See Neil’s blog post for more detail
To convert the SCN to a date/time there are various ways but Oracle will do it for you if it was within the last few days for you – with SCN_TO_TIMESTAMP function. If the row/block was last changed more than a few days ago, that function will error with ORA-08181 (I wish it just returned null rather than 08181, but then you can always wrap the call in your own function that handles that…)
Below is a short demo using test tables I don’t describe:
select house_number, addr_line_1,post_code ,ora_rowscn ,scn_to_timestamp(ora_rowscn) time_of_scn from address where house_number = 100 and addr_line_1 like 'COTHAM SOUTH%' / HOUSE NUMBER ADDR_LINE_1 POST_COD ORA_ROWSCN TIME_OF_SCN ------- -------------------- -------- ---------- ------------------------ 100 COTHAM SOUTH TERRACE SH5 8FA 11425626 24-JAN-16 20.44.56.00000 100 COTHAM SOUTH DRIVE LS20 1QY 11427281 24-JAN-16 20.51.29.00000 100 COTHAM SOUTH BD17 7JW 11437843 24-JAN-16 20.53.39.00000 100 COTHAM SOUTH TERRACE LS7 9SK 11448376 24-JAN-16 20.54.56.00000 100 COTHAM SOUTH TERRACE LS16 4SW 11460162 24-JAN-16 21.20.29.00000 100 COTHAM SOUTH TERRACE LS7 1GL 11461400 24-JAN-16 21.25.48.00000 100 COTHAM SOUTH LS20 1TO 11471921 24-JAN-16 21.26.53.00000 100 COTHAM SOUTH DRIVE LS1 5EJ 11471921 24-JAN-16 21.26.53.00000 100 COTHAM SOUTH DRIVE SG 3LO 11482461 24-JAN-16 21.28.05.00000 ... --However, if the change is more than about 120 hours ago... select surname,first_forename,dob,ora_rowscn ,scn_to_timestamp(ora_rowscn) time_of_scn from person where surname='KINOCK' and DOB between sysdate -10000 and sysdate -9500 / ,scn_to_timestamp(ora_rowscn) time_of_scn * ERROR at line 2: ORA-08181: specified number is not a valid system change number ORA-06512: at "SYS.SCN_TO_TIMESTAMP", line 1 -- which is a bit misleading as it was a valid SCN, just not for the SCN_TO_TIMESTAMP function -- remove the column based on scn_to_timestamp... select surname,first_forename,dob,ora_rowscn --,scn_to_timestamp(ora_rowscn) time_of_scn from person where surname='KINOCK' and DOB between sysdate -10000 and sysdate -9500 SURNAME FIRST_FORENAME DOB ORA_ROWSCN --------------- --------------- ----------------- ---------- KINOCK ABIGAIL 22-APR-1989 00:00 2518996 KINOCK FRANCESCA 23-APR-1989 00:00 2539749 KINOCK GIANO 10-NOV-1989 00:00 2567890 KINOCK GILLIAN 11-JAN-1990 00:00 2716278 ...
Look, you really should go and look at Neil’s post: click here
Friday Philosophy – Database Dinosaurs January 22, 2016
Posted by mwidlake in Friday Philosophy, Perceptions, working.Tags: Humour, perception, system development
14 comments
I’m guessing many of you reading this are over 40. I know some of you are actually beyond the half century and a couple of you are….older! If you are younger than 40, just print out this and put it in an envelope marked “read a decade later than {current date}”. It will have become relevant for you by then…
So wind back your memories to those glorious days in your first role working with IT. For most of us it was half our lives back or more, when we were in our early 20’s or even in our teens. One of you was 18, I know, and I knew one guy who started as a salaried, paid programmer at 16. Do you remember those old guys (and occasional gals) you met back then? Often with beards, an odd sense of “style” and a constant grumbling murmur that, if you listened closely, was a constant diatribe about the youngsters “not getting it” and this UNIX thing not being a “proper OS” {fill in whatever was appropriate for the upstart OS back when back where for you}.
You are now that person. I know, you don’t feel like it – you can still do all this technology stuff, you program better now than ever, you know how to get the job done and you have kept up with the tech as it moves forward. And you sure as hell do not look as weird as those oldsters did! Well I have bad news. You do look as weird as those old guys/gals to any youth about {and is that not a good thing, as most of them look a right state} and you have probably not kept quite so up with the tech as you think. You have to keep partly up-to-date as the versions of Oracle or whatever roll on, else the career becomes tricky. But as I’ve realised this last few weeks, you probably use old coding techniques and ways of doing things. This is maybe not a bad thing in you day-to-day job as these older ways *work* and doing it that way is quicker for you than spending time checking up the latest “time saving” shortcuts in the code you write. I’ve had that brought home to me recently as I’m working in PL/SQL at the moment and I am using some code I initially wrote back in the last century {I love saying that} as the basis of an example. It works just fine but I decided I should re-work it to remove now-redundant constructs and use features that are current. It is taking me a lot of time, a lot more than I expected, and if I was writing something to Just-Do-The-Job with slightly rusty ways, I’d have it done now. That is what I mean about it not being such a bad thing to use what you know. So long as you eventually move forward!
Of course it does not help that you work on a legacy system, namely Oracle. I am not the first to say this by a long, long shot, Mogens Norgaard started saying this back in 2004 (I can’t find the source articles/document yet, just references to them} and he was right even then. If you think back to those more mature work colleagues when we started, they were experts in legacy software, OS’s and hardware that did in fact die off. VMS went, OS/2 died, Ingress, Informix, Sybase and DB2 are gone or niche. And don’t even mention the various network architectures that we had then and are no more. Their tech had often not been around as long as Oracle has now. And I know of places that have refreshed their whole application implementation 3 or 4 times – and have done so with each one based on a later version of Oracle (I do not mean a migration, I mean a re-build).
The difference is, Oracle has had a very, very long shelf life. It has continued to improve, become more capable and the oracle sales & marketing engines, though at times the bane of the technologist’s lives (like making companies think RAC will solve all your problems when in fact it solves specific problems at other costs), have done a fantastic job for the company. Oracle is still one of the top skills to have and is at the moment claiming to be the fastest growing database. I’m not sure how they justify the claim, it’s a sales thing and I’ve ignored that sort of things for years, but it cannot be argued that there is a lot of Oracle tech about still.
So, all you Oracle technologists, you are IT Dinosaurs working on legacy systems.
But you know what? Dinosaurs ruled the earth for a very, very, very long time. 185 million years or so during the Mesozoic period. And they only died out 65 million years ago, so they ruled for three times as long as they have been “retired”. We IT Dinosaurs could well be around for a good while yet.
We better be as there is another difference between when we started and now. Back then, we youth were like the small mammals scurrying in numbers around the dinosaurs(*). Now we are the dinosaurs, there does not seem to be that many youth scurrying about. Now that I DO worry about.
(*) the whole big-dinos/small scurrying mammals is a bit of a myth/miss-perception but this is not a lesson on histozoology…
Getting Your Transaction SCN – USERENV(COMMITSCN) January 19, 2016
Posted by mwidlake in development, performance, SQL.Tags: data dictionary, performance, PL/SQL, SQL
3 comments
A few days ago I was introduced (or re-introduced) to USERENV(‘COMMITSCN’) by Jonathan Lewis. This is an internal function that allows limited access to the SCN of your transaction.
I was trying to find a way to get the actual commit SCN easily as it struck me that Oracle would have it to hand somewhere and it would be unique to the change and generated very efficiently. I could not find anything to do it so I asked Jonathan and he pointed me straight to this post he did about it a while back. What a nice chap. However, the post is from 1999 (last CENTURY!) so I thought I should just check it out first…
I’ll say up front that this is an undocumented feature of a now-deprecated function. Well, almost undocumented – older SQL reference manuals mention that ‘commitscn’ returns a NUMBER as opposed to the VARCHAR2 returned by most parameters you can use with USERENV, but it does not list it as a valid parameter for that function.
USERENV has been deprecated since Oracle 10g (see the old 10g documentation link here about USERENV) and you have been instructed to use SYS_CONTEXT(‘userenv’,’parameter‘) as described in the 12c database SQL reference manual here. However, there is no way to get the commit SCN from SYS_CONTEXT that I can find, so I thought I’d check out if USERENV(‘COMMITSCN’) still works. It does, on my version of Oracle 12.1.0.2!
There are some strict limits to this function. To begin with, you can’t select it, you can only use it on insert/update:
-- attempt a simple select of the SCN mdw> select userenv('commitscn') from dual; select userenv('commitscn') from dual * ERROR at line 1: ORA-01725: USERENV('COMMITSCN') not allowed here --But I can use in an insert, mdw> insert into test_scn (seq_no,vc1,scn_no) 2 values (100,'abcd',userenv('commitscn')) 1 row created. mdw> select * from test_scn where seq_no=100 SEQ_NO VC1 SCN_NO ---------- ---------- ---------- 100 abcd 11144739 -- Now commit my new record mdw> commit; Commit complete. mdw> select * from test_scn where seq_no=100 2 / SEQ_NO VC1 SCN_NO ---------- ---------- ---------- 100 abcd 11144753 --LOOK at the value for SCN_NO now! Compare to before the commit!
If you look at the above you will see a couple of things. The first is that, as I said, you cannot SELECT the function USERENV(‘COMMITSCN’).
The other is, though a value is put into the column when I insert a row using it, and I see that when I query the information back, it changes when I commit. This is because Oracle is recording something at the point of commit, not at the point of the SQL statement running – and the new SCN is only generated when you commit. A lot could have happened since I did the INSERT, I might have gone for a cup of tea and a batch job kicked off doing 1 million transactions, each with it’s own SCN. So though a placeholder of the current SCN is put into your view of the table row, the value put in the actual table is generated at the time of the commit.
Another limiting rule is that you can only reference USERENV(‘COMMITSCN’) once in a transaction, for one row. If I try and create 2 rows using the function in the same transaction I get an error, if I try to update more than 1 row I get an error:
mdw> insert into test_scn (seq_no,vc1,scn_no) 2 values (101,'abcd',userenv('commitscn')) 1 row created. mdw> insert into test_scn (seq_no,vc1,scn_no) 2 values (102,'abcd',userenv('commitscn')) insert into test_scn (seq_no,vc1,scn_no) * ERROR at line 1: ORA-01721: USERENV(COMMITSCN) invoked more than once in a transaction -- now test updating several records mdw> commit; Commit complete. mdw> select * from test_scn; SEQ_NO VC1 SCN_NO ---------- ---------- ---------- 1 AAAAAAA 11143743 2 AAAAAAA 11143746 3 AAAAAAA 11143749 4 AAAAAAA 11143774 5 AAAAAAA 11143777 100 abcd 11144753 101 abcd 11145543 mdw> update test_scn set scn_no = userenv('commitscn'); update test_scn set scn_no = userenv('commitscn') * ERROR at line 1: ORA-01721: USERENV(COMMITSCN) invoked more than once in a transaction -- but one row works mdw> update test_scn set scn_no = userenv('commitscn') where rownum =1; 1 row updated.
USERENV(‘COMMITSCN’) is old, undocumented and limited in use. So why am I looking at it, let alone even telling you all about it? {Apart from the fact that a lot of you *love* this sort of obscure, tid-bitty stuff}. Well, as there is no replacement for it that I am aware of. You can get the current SCN in a couple of ways, the easiest probably being to get it from V$DATABASE:
mdw> select current_scn from v$database; any key> CURRENT_SCN ----------- 11146718
However, that is the last SCN used at the time you check it and is not the SCN when you commit. ie it is a different thing. I always find it irksome on those odd occasions when something is deprecated in Oracle with nothing really to replace it.
I just demonstrate again that USERENV(‘COMMITSCN’) is a little special below, and not the same as just selecting SCN from V$DATABASE. Before I go any further, I think the value USERENV(‘COMMITSCN’) puts into the table is the actual COMMIT SCN minus 1. I mostly think this as Jonathan said so :-). I do see each time I run this test that the first select from V$DATABASE and then my insert and a commit straight away results in a value in the table 2 higher than the select.
Further iterations (2nd and 3rd in this case) show the value selected from V$DATABASE and the value inserted into TEST_SCN immediately after are the same, and are 3 higher than the previous iteration. I anticipated an increase of two, once for the change to the UNDO tablespace for the insert and once for the insert. I am not sure where the third one comes in.
However, in the fourth iteration I have a PAUSE in my SQL*Plus script between checking V$DATABASE and doing my insert and, in a second session, I do some simple inserts and commits {it does not matter what, so I don’t show it}. Thus the difference between the SCN I collected from V$DATABASE and the value inserted into the table.
Finally, in the fifth iteration, I check the value in V$DATABASE, do the insert, query it back and see the two are the same. And THEN I pause so I can do some changes and commit them in my second session. After I’ve done that I continue my first session which commits my latest insert into TEST_SCN. I check the values actually stored in the table and, just as at the top of this post, you see that the value actually preserved in the table is a later SCN than the placeholder one. It is doing something special.
(the below has the noddy code to create my test table and sequence as well as the test)
-- test_scn1 --create table test_scn (seq_no number,vc1 varchar2(10),scn_no number) -- create sequence scn_seq; select current_scn from v$database; insert into test_scn values (scn_seq.nextval,'AAAAAAA',userenv('commitscn')); commit; select * from test_scn; select current_scn from v$database; insert into test_scn values (scn_seq.nextval,'AAAAAAA',userenv('commitscn')); commit; select * from test_scn; select current_scn from v$database; insert into test_scn values (scn_seq.nextval,'AAAAAAA',userenv('commitscn')); commit; select * from test_scn; select current_scn from v$database; pause 'commit some stuff in second session and then press any key' insert into test_scn values (scn_seq.nextval,'AAAAAAA',userenv('commitscn')); commit; select * from test_scn; select current_scn from v$database; insert into test_scn values (scn_seq.nextval,'AAAAAAA',userenv('commitscn')); pause 'commit some stuff in second session again and then press any key' select * from test_scn; commit; select * from test_scn; select current_scn from v$database; -- the output of the test mdw> @test_scn1 --check V$DATABASE SCN CURRENT_SCN ----------- 11147809 -- Create and commit 1 row 1 row created. Commit complete. SEQ_NO VC1 SCN_NO ---------- ---------- ---------- 11 AAAAAAA 11147811 -- note that the inserted SCN is 2 higher than the current SCN. --Same steps, 2nd iteration CURRENT_SCN ----------- 11147814 1 row created. Commit complete. SEQ_NO VC1 SCN_NO ---------- ---------- ---------- 11 AAAAAAA 11147811 12 AAAAAAA 11147814 -- select SCN and inserted SCN are the same, 3 higher than first iteration -- same steps, 3rd iteration CURRENT_SCN ----------- 11147817 1 row created. Commit complete. SEQ_NO VC1 SCN_NO ---------- ---------- ---------- 11 AAAAAAA 11147811 12 AAAAAAA 11147814 13 AAAAAAA 11147817 -- select SCN and inserted SCN are the same, 3 higher than first iteration -- 4th iteration, a pause CURRENT_SCN ----------- 11147820 'commit some stuff in second session and then press any key' -- I did indeed change and commit some stuff in second session, before I create my record in test_scn 1 row created. Commit complete. SEQ_NO VC1 SCN_NO ---------- ---------- ---------- 11 AAAAAAA 11147811 12 AAAAAAA 11147814 13 AAAAAAA 11147817 14 AAAAAAA 11147831 -- larger gap in SCN (11147817 to 11147831 -- 5th iteration, pause now after insert and before commit CURRENT_SCN ----------- 11147834 1 row created. 'commit some stuff in second session again and then press any key' -- I did indeed change and commit some stuff in second session SEQ_NO VC1 SCN_NO ---------- ---------- ---------- 11 AAAAAAA 11147811 12 AAAAAAA 11147814 13 AAAAAAA 11147817 14 AAAAAAA 11147831 15 AAAAAAA 11147834 -- Notice the current_scn from V$DATABASE and the last row in the table match, 11147834.. Commit complete. SEQ_NO VC1 SCN_NO ---------- ---------- ---------- 11 AAAAAAA 11147811 12 AAAAAAA 11147814 13 AAAAAAA 11147817 14 AAAAAAA 11147831 15 AAAAAAA 11147842 -- But after the commit the SCN in row "15" has increased to 11147842. CURRENT_SCN ----------- 11147851 -- and the next check of V$DATABASE SCN shows the usual increase of 3 by the commit.
As you can see from the above, USERENV(‘COMMITSCN’) is doing something a little special and, despite all the limitations, I might actually have a use for it…
Friday Philosophy Guest: Open Source Projects January 15, 2016
Posted by amitzil in Architecture, Friday Philosophy, Guest Post, Perceptions.Tags: behaviour, Open Source, perception
4 comments
This post is Guest Post by my friend Liron Amitzi, an Oracle Ace, presenter and instructor who specialises in Oracle design & infrastructure. You can find his blog over here. And with that, over to you Liron 🙂
I have been wondering about open source projects for a while. I’ve talked to quite a few people about it, and still don’t really understand some of it. So I decided to write a post about my thoughts regarding this issue.
I’m not going to talk (or even mention) specific projects, but it is very interesting to me how these projects run.
During the years I have worked with quite a lot of open source software and I like some of it a lot. I completely understand how small projects work, such as text editors, small schedulers and others. With these relatively small projects, I can easily see that someone needs such software and simply sits down and writes it (alone or in a small group). When it is ready, I can see that they want to share it with the world – and open source is perfect for that. I can even understand that they will want to update it, add features, support it a little bit, etc. Another side to it that I can see is a developer that writes software to get his reputation going in the community: in order to get a job, an interesting project or simply fame.
However, I’m quite puzzled with the big open source projects, such as databases, queue management, large monitoring systems and more. I know that behind at least some of these software products, there are actual companies that invest money and people. And I don’t really understand how it works as companies need to cover their expenses, salaries, and of course, make a profit.I know that there are many ways to make money out of open source projects. Some companies charge for support, some for education & courses, and some for professional services & consulting. However, in some cases the companies that provide these services are not related to the company that sponsored the development.
So what makes a company develop or support a development of an open source project? I can think of a couple of reasons:
- As the software will be free and open source today is very common, it will get this software many potential customers and foothold
After getting a foothold, the company can charge for specific features or other complementary software. - Business decisions can also be a cause. A company that makes a lot of money from software might decide to give some back to the community so people will “like” the company more.
Still, when it is a big software project and requires a lot of resources, I can’t see why a big company will go for open source.
- First, they can make it a freeware without releasing the code.
- Second, at the bottom line, they will have to make money on this somehow.
So, if they release the project as an open source but charge for education or professional services, I guess that the education and professional services will cost more, so at the end they will make the same amount (and we will pay the same amount) as with licensed software and cheaper courses and professional services.
Am I missing something?
What do you think? I’d love to know.
About Liron
Liron Amitzi is originally from Israel and now lives in Canada with his wife and two children. I met Liron at the UKOUG Irish User Group conference in Dublin last year and again at Oracle Open World 2015, when it struck me that he looks a lot like Steven Feuerstein (Liron is on the left). Liron has been an Oracle ACE since 2009 and has helped run the Israel Oracle User Group since 2011. He specialises in High Availability solutions, design, infrastructure, performance and recovery. As well as presenting he is also an instructor and lecturer in Oracle course.