Query regarding random function
I am doing a random function this is what i hv done
static Random svcRand;
a=svcRand.nextInt();
its working perfectly but every time a random number is generated its a huge number......How can I keep it within a limit say between 1 and 100 always
showstopper wrote:
I am doing a random function this is what i hv done
static Random svcRand;
a=svcRand.nextInt(); This code would generate a NullPointerException, but I guess you initialize this somewhere.
>
its working perfectly but every time a random number is generated its a huge number......How can I keep it within a limit say between 1 and 100 alwaysThere are two ways
1. Easy: a = svcRand.nextInt(100) + 1; // number between 1 and 100
2. More general:
double start = ...;
double span = ...;
double val = svcRand.nextDouble() * span + start;
Similar Messages
-
A query regarding synchronised functions, using shared object
Hi all.
I have this little query, regarding the functions that are synchronised, based on accessing the lock to the object, which is being used for synchronizing.
Ok, I will clear myself with the following example :
class First
int a;
static int b;
public void func_one()
synchronized((Integer) a)
{ // function logic
} // End of func_one
public void func_two()
synchronized((Integer) b)
{ / function logic
} // End of func_two
public static void func_three()
synchronized((Integer) a)
{ // function logic
} // End of func_three, WHICH IS ACTUALLY NOT ALLOWED,
// just written here for completeness.
public static void func_four()
synchronized((Integer) b)
{ / function logic
} // End of func_four
First obj1 = new First();
First obj2 = new First();
Note that the four functions are different on the following criteria :
a) Whether the function is static or non-static.
b) Whether the object on which synchronization is based is a static, or a non-static member of the class.
Now, first my-thoughts; kindly correct me if I am wrong :
a) In case 1, we have a non-static function, synchronized on a non-static object. Thus, effectively, there is no-synchronisation, since in case obj1 and obj2 happen to call the func_one at the same time, obj1 will obtain lock for obj1.a; and obj2 will obtain lock to obj2.a; and both can go inside the supposed-to-be-synchronized-function-but-actually-is-not merrily.
Kindly correct me I am wrong anywhere in the above.
b) In case 2, we have a non-static function, synchronized on a static object. Here, again if obj1, and obj2 happen to call the function at the same time, obj1 will try to obtain lock for obj1.a; while obj2 will try to obtain lock for obj2.a. However, since obj1.a and obj2.a are the same, thus we will indeed obtain sychronisation.
Kindly correct me I am wrong anywhere in the above.
c) In case 3, we have a static function , synchronized on a non-static object. However, Java does not allow functions of this type, so we may safely move forward.
d) In case 4, we have a static function, synchronized on a static object.
Here, again if obj1, and obj2 happen to call the function at the same time, obj1 will try to obtain lock for obj1.a; while obj2 will try to obtain lock for obj2.a. However, since obj1.a and obj2.a are the same, thus we will indeed obtain sychronisation. But we are only partly done for this case.
First, Kindly correct me I am wrong anywhere in the above.
Now, I have a query : what happens if the call is made in a classically static manner, i.e. using the statement "First.func_four;".
Another query : so far we have been assuming that the only objects contending for the synchronized function are obj1, and obj2, in a single thread. Now, consider this, suppose we have the same reference obj1, in two threads, and the call "obj1.func_four;" happens to occur at the same time from each of these threads. Thus, we have obj1 rying to obtain lock for obj1.a; and again obj1 trying to obtain lock for obj1.a, which are the same locks. So, if obj1.a of the first thread obtains the lock, then it will enter the function no-doubt, but the call from the second thread will also succeed. Thus, effectively, our synchronisation is broken.
Or am I being dumb ?
Looking forward to replies..
Ashutosha) In case 1, we have a non-static function, synchronized on a non-static object. Thus, effectively, there is no-synchronisationThere is no synchronization between distinct First objects, but that's what you specified. Apart from the coding bug noted below, there would be synchronization between different threads using the same instance of First.
b) In case 2, we have a non-static function, synchronized on a static object. Here, again if obj1, and obj2 happen to call the function at the same time, obj1 will try to obtain lock for obj1.a; while obj2 will try to obtain lock for obj2.a.obj1/2 don't call methods or try to obtain locks. The two different threads do that. And you mean First.b, not obj1.b and obj2.b, but see also below.
d) In case 4, we have a static function, synchronized on a static object. Here, again if obj1, and obj2 happen to call the function at the same time, obj1 will try to obtain lock for obj1.a; while obj2 will try to obtain lock for obj2.a.Again, obj1/2 don't call methods or try to obtain locks. The two different threads do that. And again, you mean First.b. obj1.b and obj2.b are the same as First.b. Does that make it clearer?
Now, I have a query : what happens if the call is made in a classically static manner, i.e. using the statement "First.func_four;".That's what happens in any case whether you write obj1.func_four(), obj2.func)four(), or First.func_four(). All these are identical when func_four(0 is static.
Now, consider this, suppose we have the same reference obj1, in two threads, and the call "obj1.func_four;" happens to occur at the same time from each of these threads. Thus, we have obj1 rying to obtain lock for obj1.aNo we don't, we have a thread trying to obtain the lock on First.b.
and again obj1 trying to obtain lock for obj1.aYou mean obj2 and First.b, but obj2 doesn't obtain the lock, the thread does.
which are the same locks. So, if obj1.a of the first thread obtains the lock, then it will enter the function no-doubt, but the call from the second thread will also succeed.Of course it won't. Your reasoning here makes zero sense..Once First.b is locked it is locked. End of story.
Thus, effectively, our synchronisation is broken.No it isn't. The second thread will wait on the same First.b object that the first thread has locked.
However in any case you have a much bigger problem here. You're autoboxing your local 'int' variable to a possibly brand-new Integer object every call, so there may be no synchronization at all.
You need:
Object a = new Object();
static Object b = new Object(); -
Query regarding sys_context function
Hello
I have created report with custom folder and parameters are passed using sys_context function. I have few queries regarding this.
1) How to see actual sql query executed by report. I can see from discover administorator - sql inspector. But it is not showing which is value passed for sys_context parameter. If want to see query with full parameter then what to do? I have also tried to look it from toad - session browser, there also it is not showing parameter value.
2) If anything special needed to manage sys_context variable. i.e i have executed report with parameter 1 = A and now next time executed with parameter 1 =b. Will it takes proper value, i mean sys_context parameter will be refreshed itself, or need to do somehting..
Please help me out.
Thanks in advanceHi,
How to see actual sql query executed by reportSYS_CONTEXT returns values from a namespace. Normally you create a local namespace and values in this namespace can only be retrieved by the session. So there is no way to see the values for a Discoverer session from Toad. Normally, one would create a Discoverer report that returns all the values in your namespace that you can use for debugging.
If anything special needed to manage sys_context variableNo, once you have set the context in the namespace using DBMS_SESSION.set_context then it is there for the rest of the session.
Rod West -
Query regarding oracle functions
Hi All,
I ahve been trying to work with decode and NVL to get the following output:
Value Output
NULL 1
0 1
1 1
2 2
3 3
for this i have written the below query:
SELECT DECODE(NVL(high_value,1),0,1,NVL(high_value,1)) from tab1;
Can there be any alternate to this using other functions?
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Solaris: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
Thanks
NikhilUse CASE
with t_data as
select null as val from dual union all
select 0 from dual union all
select 1 from dual union all
select 2 from dual union all
select 3 from dual
SELECT
val,
CASE
WHEN (val IS NULL ) OR ( val = 0 )
THEN
1
ELSE
val
END AS output
FROM
t_data;
VAL OUTPUT
1
0 1
1 1
2 2
3 3 -
Query regarding Min function with Date
Dear All,
I have written query as follows but it is giving me error message.
Selection CityCode, CityName, Min(Date)
from Entry
I want to write a query which should generate minimum date of transactions of city. There are about 50 cities in the Entry table and against each city there are thousands of records, I want to display only the oldest date against each city with its code. In the out put there should 50 rows as there are 50 cities and oldest (min) date. Can any one please help on this SQL.
ThanksDo you want just min date in the table or need grouping by citycode and city name also?
If just min date of the table is needed, use row_number analytic function to get the min date in the table. -
All,
Can I know the difference between the following two queries
select TO_CHAR(TRUNC(sysdate),'dd-mon-rr') from dual;
select TO_CHAR(TRUNC(sysdate),'dd-mon-yy') from dual;
However, both the query gives the same result as '03-nov-09'.
Regards
ND...of which century?
SQL> var dt varchar2(10)
SQL>
SQL> begin
2 :dt := '03-11-51';
3 end;
4 /
PL/SQL procedure successfully completed.
SQL>
SQL> select TO_CHAR(to_date (:dt, 'dd-mm-rr'),'dd-mon-yyyy') from dual;
TO_CHAR(TO_DATE(:DT,
03-nov-1951
SQL>
SQL> select TO_CHAR(to_date (:dt, 'dd-mm-yy'),'dd-mon-yyyy') from dual;
TO_CHAR(TO_DATE(:DT,
03-nov-2051Don't use a two digit year... -
query regarding function module SPOOL_RQ_READ_BAPI_EXPORTS (EBP-SRM Module)
shopping cart
Hi in FM SPOOL_RQ_READ_BAPI_EXPORTS
i want to relate the internal tables requisition_items and requisition_services.
but in am not getting the key on which they should be joined
here i have to take the quantity and other fields from requisition_services
right now i am using the joining condition as
requisition_items-pckg_no = requisition_services-pckg_no.
any help in this regard is welcome.
Thanks and regards,
VithalprasadHi Kathirvel,
Thank you for reply. I am making changes for standard code only.
" Call FM SPOOL_DPO_READ_BAPI_EXPORTS to read PO data exported to backend.
Use this data to call FM B46B_DPO_TRANSFER and copy errors tab from
' lt_bapi_return ' to ' et_messages' retrun tab in 'doc_check' badi. "
Thank you.
Regards, Sunu -
SQL Query (pl/sql function body returning Sql query)
Hi All,
I have created a region of "SQL Query (pl/sql function body returning Sql query)" type and it is working fine , but when I am migrating(export /import) this application from development to systest environment ,
It gives error for this region :
Error ERR-1101 Unable to process function body returning query.
OK
ORA-06550: line 1, column 52: PLS-00306: wrong number or types of arguments in call to 'FU_TRADE_REPORT_QUERY' ORA-06550: line 1, column 45: PL/SQL: Statement ignored
Any pointer ...why this is happening.
Thanks
DikshitIf your function is a stored function that is called from within APEX (function body not coded into the app itself), have you made sure that the function has been created and compiles ok prior to installing your apex app.
If there are some dependency issues between other PL/SQL units or database objects that are causing your function not to be compiled, you apex install will fail as you are trying to reference an uncompelled bit of pl/sql.
Let me know how you get on
Regards
Duncan -
SQL Query ( PL/SQL function body returning query ) page
Hello Friends,
I have a page with type SQL Query ( PL/SQL function body returning query ).
I have written a pl/sql block that returns a sql query - select statment.
Some times i am getting no data found error - does it got to do with the variable that stores the query .
=======================
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
Error ERR-1101 Unable to process function body returning query.
OK
=====================
When the query is returned with records where exactly the records are stored is it in the variable declared in pl/sql block or with the Oracle Apex implicit cursor.
Here's the pl/sql block ..
The query is generated while the user is navigating through pages ..
====================
declare
l_return_stmt varchar2(32767);
l_select varchar2(32000);
l_from varchar2(32000);
l_where varchar2(32000);
l_order_by varchar2(32000);
l_stmt_recordcount varchar2(32000);
l_recordcount number ;
begin
l_select := 'select '||:P10_VARLIST1||:P10_VARLIST2||:P10_VARLIST3
||:P10_VARLIST4||:P10_VARLIST5;
l_from := ' from '||:P10_RELATION;
if length(:P10_WHERE) > 0 then
l_where := ' where '||:P10_WHERE;
else
l_where := '';
end if;
if length(:P10_ORDER_BY) > 0 then
l_order_by := ' order by '||:P10_ORDER_BY;
else
l_order_by := '';
end if;
l_return_stmt := l_select||l_from||l_where||l_order_by;
:P10_STMT := l_return_stmt;
return l_return_stmt;
end;
=============================
Appreciate your help in this regard.
thanks/kumar
Edited by: kumar73 on Apr 22, 2010 6:38 AMIt looks like the query string you are trying to pass back exceeds the 32K limit for a varchar. Where this is happening is kind of difficult to tell as it could be any number of points, and also depends on what you are passing into the process via page items.
I would first try to establish what combination of page items causes this error to occur. Then, starting from the bottom and working your way backwards, I would start 'switching off' some of the items you use to build your query until it breaks again, thus establishing which part is leading to the error.
Also, I'm not sure what :P10_STMT is doing (are you maybe using this for visiblity of the query created)?
It looks like the query string you are trying to pass back exceeds the 32K limit for a varchar. Where this is happening is kind of difficult to tell as it could be any number of points, and also depends on what you are passing into the process via page items.
I would first try to establish what combination of page items causes this error to occur. then, starting from the bottom and working your way backwards, I would start 'switching off' some of the items you use to build your query until it breaks again, thus establishing which part is leading to the error.
Also, I'm not sure what :P10_STMT is doing (are you maybe using this for visiblity of the query created)? -
SQL Query (PL/SQL Function Body returning SQL query) doesn't return any row
I have a region with the following type:
SQL Query (PL/SQL Function Body returning SQL query).
In a search screen the users can enter different numbers, separated by an ENTER.
I want to check these numbers by replacing the ENTER, which is CHR(13) || CHR(10) I believe, with commas. And then I can use it like this: POD IN (<<text>>).
It's something like this:
If (:P30_POD Is Not Null) Then
v_where := v_where || v_condition || 'POD IN (''''''''||REPLACE(''' || :P30_POD || ''', CHR(13) || CHR(10), '','')||'''''''''')';
v_condition := ' AND ';
End If;
But the query doesn't return any rows.
I tried to reproduce it in Toad:
select * from asx_worklistitem
where
POD IN (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
==> This is the query that does't return any rows
select (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
from dual;
==> This returns '541449200000171813','541449206006341366'
select * from asx_worklistitem
where pod in ('541449200000171813','541449206006341366');
==> and when I copy/paste this in the above query, it does return my rows.
So why does my first query doesn't work?
Doe anyone have any idea?
Kind regards,
Geert
Message was edited by:
ZorryThanks for the help.
I made it work, but via the following code:
If (:P30_POD Is Not Null) Then
v_pods := REPLACE(:P30_POD, CHR(13) || CHR(10));
v_where := v_where || v_condition || 'POD IN (';
v_counter := 1;
WHILE (v_counter < LENGTH(v_pods)) LOOP
v_pod := SUBSTR(v_pods, v_counter, 18);
IF (v_counter <> 1) THEN
v_where := v_where || ',';
END IF;
v_where := v_where || '''' || v_pod || '''';
v_counter := v_counter + 18;
END LOOP;
v_where := v_where || ')';
v_condition := ' AND ';
End If;But now I want to make an update of all the records that correspond to this search criteria. I can give in a status via a dropdownlist and that I want to update all the records that correspond to one of these POD's with that status.
For a region you can build an SQL query via PL/SQL, but for a process you only have a PL/SQL block. Is the only way to update all these records by making a loop and make an update for every POD that is specified.
Because I think this will have a lot of overhead.
I would like to make something like a multi row update in an updateable report, but I want to specify the status from somewhere else. Is this possible? -
Hi,
We are on R12 and I have have a query regarding balances.
I am writing a report and need to get the functional Actual balance(GBP) for accounts.
Each account has a balance in one or more currencies. My understanding as per the TRM was that the period_net_dr/cr columns stores the balances in ledger currency for all Journals entered and posted in GBP, while the period_net_dr_beq and period_net_cr_beq stores the ledger equivalent balance for all Journals entered and posted in Foreign currency.
However, when I query gl_balances, I notice the following :
1) For a ccid, for GBP currency code, the period_net_dr_beq and period_net_cr_beq are being populated , why ?
2) For certain ccid, for GBP currency code the period_net_cr_beq and period_net_dr_beq both are zero, though there is a value in the period_net_dr/cr columns.
3) When I do an account inquiry from GL SuperUser, I can see that for a given period and account and for Currency type 'Entered' , the Balances window shows me the
result of period_net_dr_beq-period_net_cr_beq columns for my GBP balance.
I am a bit confused and would appreciate if someone can point me what am I missing ?
ThanksOK, I have managed to figure this one out.
The period_net_cr / period_net_dr stores the sum of functional balances(includes the GBP journals + the functional equivalent of the non gbp journals) . Its like a running total of the functional balance. -
Query regarding DB_16k_CACHE_SIZE
Hi Friends,
I have got a urgent query regarding db_16k_cache_size parameter.I have created a tablespace with 16k block size,and i have configured the db_16k_cache_sieze to 208M accordingly.I have kept a table in this tablesspace whose presenet size is 323 GB.Some complex queries will be running on this table comprising groups,some complex joins,ordes,analytical functions etc.
I am having 8 GB of SGA.Now my query is whether i have to increase the db_16k_cache_szie parameter from its present size to get better performance and if it is then how to detemine what will be the optimal size of db_16k_cache_size.
Please help...
Thanks
somyPost your query what u have tried. Then only we might be help with you
-
Query regarding moving components
I have a JPanel (call it panel1) in another JPanel which has setlayout(null).
i want to be able to "drag" around panel1 in the other panel.
i used a quick method of adding a MouseMotionListener to panel1, and under mouseDrag(mouseevent e) had the panel just reset its setLocation to the current getX getY coordinates.
This method does not work well, with the panel flickering abit, and not following the mouse too well, and even at some points jumping to a random location.
Whats the best way of achieving this?
thanks for any help in advanceHi,
Thank you very much for the response. I have a query regarding the same. If i am making changes only in one single report and i am moving it to the quality. Now again i am making changes in the same report and saving it in a different request and moving it to the production. in this case, i wanted to know whether the whole changes made in the first and second request will reflect in the production or only the 2nd request's change will only reflect (since it is only a single report. there is no include in the program)
Kindly send ur suggestions.
Best regards,
John -
Self-join query to Analytical function query
Hi All,
I have converted a self-join query to Analytical function query due to the performance reasons.
Query which is using Analytical function is giving the correct count as I compared it with query using Self-Join. Can you please tell what is wrong in the query.
==========================
Query using Self-Join
select count(1)
From (select t1.*, max(t1.dw_creation_dt) over (partition by t1.empl_id) pers_max_date
from ohr_pers_curr t1 ) pers
, (select t2.*, max(t2.dw_creation_dt) over (partition by t2.empl_id, t2.empl_rcd) job_max_date
from OHR_JOB_CURR t2) job
where pers.empl_id = job.empl_id
and pers.dw_creation_dt=pers.pers_max_date
and job.dw_creation_dt=job.job_max_date
and job.dummy_row_flag = 'N'
and pers.dw_creation_rsn_cd in ('N', 'U')
and job.dw_creation_rsn_cd in ('N', 'U')
================================================
Query Using Analytical function
select count(1)
From (select t1.*, max(t1.dw_creation_dt) over (partition by t1.empl_id) pers_max_date
from ohr_pers_curr t1 ) pers
, (select t2.*, max(t2.dw_creation_dt) over (partition by t2.empl_id, t2.empl_rcd) job_max_date
from OHR_JOB_CURR t2) job
where pers.empl_id = job.empl_id
and pers.dw_creation_dt=pers.pers_max_date
and job.dw_creation_dt=job.job_max_date
and job.dummy_row_flag = 'N'
and pers.dw_creation_rsn_cd in ('N', 'U')
and job.dw_creation_rsn_cd in ('N', 'U')
==================================Hi David,
The base is same but the problem is different.
As far as implementation concern these queries looks same, but when I see there counts, they do not match. I do not have any reason why this happening.
Regards
Gaurav -
Query regarding updation thru a Procedure
Hi,I have a query regarding updation.
1.I invoke a procedure in Oracle called submit thru my Java application.
The submit procedure saves the XML data in the database
and displays this data in a Front End GUI.
2. Now,I make a change in my Java application by adding new elements to the same row.This row now contains additional XML elements.
I would like to display the new row with the new elements in the GUI.
What is a better option for doing the above?
1.Delete the row being shown,save the new row with the changes in the database,and re display it?
2.Or,Update the row dynamically and refresh?
Any suggestions
Thanks,Hi,I have a query regarding updation.
1.I invoke a procedure in Oracle called submit thru
my Java application.
The submit procedure saves the XML data in the
database
and displays this data in a Front End GUI.
2. Now,I make a change in my Java application by
adding new elements to the same row.This row now
contains additional XML elements.
I would like to display the new row with the new
elements in the GUI.
What is a better option for doing the above?
1.Delete the row being shown,save the new row with
the changes in the database,and re display it?
2.Or,Update the row dynamically and refresh?
Any suggestions
Thanks,If you delete (it seems to me yours this process is regular and frequent) and re insert the new updated one record then High water mark will cause to scan yours table which may cause to degrade the performance.AFAIK you should go with update.But hold down dont implement it as i suggested lets see what are others solution here which may be more precious then mine.
Khurram
Maybe you are looking for
-
SAP HANA Input parameters in SAP BO Analysis
Hi, dear experts. Please help me with one problem in SAP BO Analysis. Problem is: in sap hana studio i made calculation view that has some input parameters (Param. type - Direct, Sematic Type - Date, Data type - Date). Then i made filter with this pa
-
Hi After applying group level security in business view I am unable to use list of values. I am using Crystal Reports XI Release 2. Any ideas why this occurs. Wini
-
Parse errors on 'white space' when migrating procs/triggers from Sybase
getting: Error occurred on line nn: oracle.mtg.sybase12.parser.ParseException: Parse error at line nn, column 1. Encountered: looks like this happens for every proc/trigger that has a blank line at the end of its text. anyone know of any fix/workarou
-
We have the SECTOR field and LEGISLATION field on the PCUI application screen, for a specific sector (selected in the SECTOR dropdown screen field) we want only legislations for that specific selected sector to be in the LEGISLATION dropdown list. Bo
-
Add push button to Serial number tab in migo transaction
Hi all, I need to add an upload push button to the tab screen of serial numbers in migo transaction.Is there any exit, or badi,or enhancement spot for this. Thanks & regards, Srilakshmi.