Tag Archives: sql

oracle read queue jms data

queues… only triggers are more confusing… ok thats wrong… because i learned stuff about queue_schedulers… pretty scary… but thats something completely different and i actually hope, i dont have to write about these… but back to queues…

queue handling is in my point of view pretty strate forward… define a queue message, write a queue writer to put messages in the queue, write a reader to retrieve the messages from the queue… simple… but checking, whats acutally going on on the queue is difficult…

we have sys_aq$_jms_text_messages in the queue, which is actually shown on the queue_table when you do a select on it… great… so how can i get its content?

select msgid, enq_time, enq_uid, qt.user_data.TEXT_VC from MY_QUEUE_TABLE qt where q_name = ‘my_queue’

where as the qt needs to be written out…

jpa nativeQueries

Sometimes JPQL just isnt enough… JPQL is rendered differently then expected, ie nested selects dont work… so native SQL queries need to be done…

main problem is the return value. It is possible to define SqlResultSetMappings, but these where kinda confusing. had problems with primary keys… so without these structures, a typeless list of object-array is returned:

   final List result = entityManager.createNativeQuery(“SELECT a, b FROM table”).getResultList(); 

for each row an Object[] is put into the list.The Array contains Objects of a and b.

SQL having

I needed to select an object-id of a row where a value reached a max value. Kinda confusing, so example:

SELECT id, MAX(value) FROM table
GROUP BY id

simple… and now i needed to check, if the value is bigger then something… lets say 5:

SELECT id FROM (
       SELECT id, MAX(value) AS bigValue FROM table
       GROUP BY id)
WHERE bigValue > 5

and yes. A join would be fine too… but actually i needed this query in JPA. and JPQL can’t handle nested selects… so a different solution was needed: HAVING! having is a select on a group…

SELECT id FROM table
GROUP BY id
HAVING MAX(value) > 5

cool 🙂 JPA didnt handle the HAVING… 🙁

ea: database model: create index

and enterprise architect can add indexes… just right-click on the table and select operations… und create the index… its a bit fency, because you need to create it, then select it, then tab to Column, and then you can select the columns, which need to be indexed… its confusing, because you select something on one tab, and then select other things on other tabs…

ea oracle datatypes

as i told you before… working with enterprise architect and creating a database model for an oracle 11g database… and ea doesnt have the “timestamp” datatype… wft? so tried to figure out, if there is an ea update for newer oracle platforms… fail… but found this… exactly the same problem…

and a really simple solution… just define a new datatype:

Menu Settings->Database Datatypes

And define the database type for oracle…

simple… but spooky…

database modeling with enterprise architect

so finally got an Spary Enterprise Architect 🙂 the “:)” is kinda relative, because i really dont care, which program i should use for modeling tables and creating ddl’s… but the project said: use ea… and so i did… installing software in a really big company (as i am working now) can be really a pain… but after a few days, i got it up and runing… finally… so its kinda “:)”

and i think its really good… had a few problems in the beginning, created a table and colums, but couldn’t set columntypes, but master this problem… the table needs to know, which database it is in… kinda clear, but i thought the definition should be somewhere on the project or on the schema… not directly on the table…

so currently “painting” my model 🙂

moving ms sql server

we needed to move an sql server… so we looked for space in our virtual environment… there was… but wth? moving is renaming… or isnt it? first it looked like it was, but secondly there were a few problems…

basiclly the sql server instance has the same name as the server… wrong!

sp_dropserver ‘old_name’
GO
sp_addserver ‘new_name’, local
GO

this statements change the instance name… following command returns the current instancename…

select @@SERVERNAME

and thats the history of renaming ms sql servers… funny…

ms sql timeout

ok we had a problem on an application… it was really slow and sometimes it resulted in a sql timeout. so sql server(MSSQL 2008 R2) must be slow… no wasnt… network must be slow… no wasnt… app server must be slow… no wasnt… app must be slow… good point… but isnt…

after reading and debuging the sourcecode(code was not mine and coder is on vacation(as usual, when problems pop up…)) the slow sql statement was a view… running the view in the ms sql management studio: instant… hmm… wtf? after a few more tests we figured out, that the problem is based on the sql servers client, and a little bit of randomness…. running the statement on the sql server was instant… running it locally on a computer 23 seconds!.. running it on a virtual maschine, on the same computer… instant… wth? and always in ms sql management studio…

after a few more tries, we saw, that the result of the viw is unsorted… adding a “order by” resulted in the same process speed on all boxes… WTF? but yeah… its the damn solution…