Coldfusion query and assign rows to a session [closed] - oracle

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have come across a strange requirement, and really haven't a clue where to begin
We have an oracle database table that will be receiving data daily, and a CF application to interface with it
What they would like is for when a user logs in, to show x amount of rows from the table, and essentially "lock" the x amount of rows to that user, so when another user logs in, their x amount of rows are different, so noone is working concurrently on the same row
What i am guessing is a session write to a table, claiming the rows, but any thoughts would be more than welcome

There are a few ways to approach this problem. I will take a nibble here and tell you that you will need to get into Oracle database procedures and requires you to understand locking select for update clauses which you will immerse you in the nuances of sessions and how they work in oracle and you will call it using cfstoredproc.
There is another method. Now I have no idea about your coding environment or restrictions, nor do I know the user/system load considerations so this is just a suggestion. Adding a flag field to the table and make it a bit datatype or int...whatever. You are going to select them in a cfquery, then update the list of ids (setting bitItnFlag=1 ...or whatever you want to name this new field) which will mean 'this record is checked out'. You will still have the group of records in the first query which you will loop out to the end user to work with needing an update query setting them free by setting your bitIntFlag=0. They will be essentially locked. So another user will have to select where bitIntFlag=0 essentially skipping your locked group and setting their selected group (update them equal to 1). You can use cftransaction and two cfqueries like this.
<cftransaction action"begin">
<cfquery name="selectLock" datasource="#application.dsn#">
SELECT *
FROM (
SELECT *
FROM mytable
WHERE bitIntFlag = 0
ORDER BY
dbms_random.value
)
WHERE rownum <= 10
</cfquery>
<!---Now run your update--->
<cftry>
<cfquery name="updateLock" datasource="#application.dsn#">
UPDATE
myTable
SET
bitIntFlag = 1
WHERE
primaryKeyIDthing in #ValueList(selectLock.name)#
</cfquery>
<cfcatch type="database">
<cftransaction action="rollback"/>
</cfcatch>
<cftry>
<cftransaction action="commit"/>
</cftransaction>
<cfoutput query="selectLock">
#primaryKeyIDthing#<br>
</cfoutput>
(this code is untested but should get you started if you go down this route)
When you are done you update your records using cfquery and run your update sql and set the flag to zero to free up the records.
Again this is a simple work around that may or may not work for you. I don't know what kind of transactional intensity you are dealing with in your environment but sometimes making things simple can work!

Related

How to delete the contents of the table in oracle using UPDATE command? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm trying to delete the contents of the entire table using UPDATE command please help me out with this...
I tried using SET clause and tried to set all the fields to NULL value..But its not Working please tell Me
You cannot delete rows using UPDATE command. You can empty them - set NULLs to all columns, but rows remains in the table. Use
DELETE your_table;
all rows in your_table will be deleted.
if you are so sure you are not going to need this data anymore. [faster]
truncate table [table_name];
This one will generate redo and you could rescue data with -flashback to time- or -flashback table to beofre drop-
delete [table_name];
Regards.

Using temporary table in Stored procedure [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have written stored procedure and it takes long time when i call it.
I use temporary table in 'SP'.
it can be reason ??
CREATE OR REPLACE PROCEDURE TEST_SP
IS
BEGIN
INSERT INTO MYTEMP_table (A, B )
( SELECT id AS CUSTOMER_NO,
ACC_NO AS ACCOUNT_NO
FROM myTable );
UPDATE MYTEMP_table
SET MYTEMP_table.A =
( SELECT MIN (BRH_DATE)
FROM CUSTOMER,)
UPDATE MYTEMP_table
SET MYTEMP_table.B =
( SELECT MIN (SUBSTR (ENTRY_DATE, 0, 8))
FROM INFO)
.......
MYTEMP_table is temporary table.
This code snippet looks woefully incomplete. Seems odd that you are filling the temp table with one query:
select id, acc_no from myTable
and then wiping out all columns with a single value:
UPDATE MYTEMP_table
SET MYTEMP_table.A =
( SELECT MIN (BRH_DATE)
FROM CUSTOMER,)
Your post is not clear, but hopefully you are using a global temporary table (Memory based) rather than a physical table meant for temporary storage.
Multiple writes to the same rows is a sure-fire way of slowing down the works (Much more-so in a physical table, but still slow either way). If possible, consider the following:
Use analytic functions or a more complex initial query to get all your writing done up front...
If you're not comfortable/familiar with running/reading explain plans, try running each SQL statement in a SQL Editor manually to assess their individual performance...

What is the order in which oracle executes the update in statement?

I am trying to resolve a deadlock issue between two processes by trying to ensure that they lock the DB rows in order so one can finish before the other.
To do that, I am trying to determine how Oracle processes this statement:
update table_a
set col_2 = 'hello'
where col_1 in (1,2,3,4,5,6,7,8,9,10);
When this statement is executed, in what order does Oracle lock and update the rows? If you can point me in the direction on how to determine this, I'd be glad to do it myself.
I am posting this question because I did not find an answer in my Google search or elsewhere on this site, of course.

multiple queries regarding Oracle Views and Grants [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Multiple questions - so please excuse if the post gets long
have a read only access to an Oracle schema where I can see certain views
Say views 'X' and 'Y'
now need to create a View on top of these 2 views
1 >Not sure if from performance perspective this is a good idea ?
( the new view will be used for firing selects only )
The two existing views 'X' and 'Y' are themselves created off some other views 'A' and 'B' !!
The weird thing is I can fire a query like :
select * from <<schema_name>>.X
2 >However I cannot access the view A or B directly - so do I need to have grants to A and B ?
when I look at the DDL statement for View X and View Y I see the following code :
create view <<schema_name>>.X as
select emp_first_name,emp_last_name,
from <<schema_name>>.A
However when I fire a query like this :
select * from <<schema_name>>.X -
I get results like :
first_name,last_name
3 >Confused about why the results show field names like first_name,last_name when the view has it defined as emp_first_name and emp_last_name ?
1> Views on Views might cause some performance issues, deppends mostly on the inner views.
Read more in this AskTom post
2> This is not wierd - that's what views do, instead of letting you select the whole table, they let you select only part of it. So you need grants on A and B.
3> Strange, Try this query and see how it was really created-
select dbms_metadata.get_ddl('VIEW', 'X', '<<schema_name>>')
from dual

Oracle data paging optimization [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
select * from (
select t_tmp_a.*, rownum t_tmp_id from (
select t.*, i.counts
from table1 t, (select id, count(id) counts from table2 group by id) i
where t.id=i.id and t.kindid in (0,1,3) order by t.id desc
) t_tmp_a where rownum <= 20) t_tmp_b where t_tmp_id >= 11;
table1 and table2 have more then 2 million data per table, when execute this query need 18s , before this query execute we should calculation total count need about 7s, so it spends more than 25s, any idea to optimiza it?
Pagination is usually a mechanism for displaying a result to a human being. No human being wants to read two million rows of data.
So if this query is indeed presenting rows to a real person then what you need to address is reducing the size of the whole result to something which is human-sized. So you need to apply additional filters in the database and return a focused result set. Not only will your users thank you, so will your network administrator.
On the other hand, if the intended recipient of this data deluge is a computer or other mechanical device then just give it the whole thing. Machines mostly don't care about pages, or if they do (spreadsheets, printers, etc) they have built-in sub-routines to handle pagination for us.
So that leaves us with the problem that your original query takes a long time to execute. Without any explain plan or statistics (how many rows in table1 fit the search criteria? how restricting are those values for kindid?) it is hard to solve this.
"kindid is a type which only have three choose(0,1,3)"
Fnord. If KINDID can only have three choices what is the point of using it in the WHERE clause?
In fact removing it from the WHERE clause may dramatically improve the performance of your query. Unless you have gathered histograms for that column Oracle will assume that in (0,1,3) is somehow going to restrict the result set; whereas that is only going to be true if the majority of rows have a NULL in that column. If that is the case it would be better to use kindid is not null.

Resources