ORACLE detecting duplicate data even the text is lower or uppercase - oracle

I'm using ORACLE database. How to detect duplicate data even the text is lower or uppercase.
Assuming on my table already inserted : Production
Now I want to add: production (with lower case), it should be detect duplicate. In my current case, it was not detected and inserted.
Here is the sample query:
SELECT * FROM tb_departments WHERE DEPARTMENT_NAME = '" . $getDepartmentName . "';
Anyone have an idea?

You can use the UPPER (or LOWER) function, which capitalize your string, i.e.
SELECT * FROM tb_departments WHERE UPPER(DEPARTMENT_NAME) = UPPER('" . $getDepartmentName . "');
As small variation you could capitalize your input string in the code and use
SELECT * FROM tb_departments WHERE UPPER(DEPARTMENT_NAME) = '" . $yourUpperDepartmentName . "';
Moreover I suggest you use query parameters, instead of injecting directly the parameters string ($getDepartmentName ) in your query.

Related

How to use MIN() function of postgresql using java code

I need to find the minimum value from a table . How to use that using java.
databaseClient.sql("Select MIN (employee_salary) " +
"from " + schema + ".employee_instances where employee_id =:employeeId")
This gives me error when i execute my code -
ERROR-
"Column name 'employee_salary' does not exist in column names [min]",
#a_horse_with_no_name's comment above helped resolve my problem:
it seems your Java code tries to retrieve a column named employee_salary but your query does not have such a column (only a column named min). You will need a column alias if that is the case: min(employee_salary) as employee_salary

H2 MUCH SLOWER than HSQLDB in my Java application? (both inmem)

I am sure there's something stupid from my side going on here.
I have a Java application where I need to query a collection of 2,5 Million objects repeatedly all the time, therefore I put them into an in memory db.
For this purpose I tried out
hsqldb
v2.4.1
and
h2
v1.4.198
For both I use exactly the same create table:
String createRateTable = "CREATE MEMORY TABLE INTEREST_RATES " +
"(EFFECTIVE_DATE DATE not NULL, "
+ "INTEREST_RATE DOUBLE, "
+ "INTEREST_RATE_CD BIGINT, "
+ "INTEREST_RATE_TERM BIGINT, "
+ "INTEREST_RATE_TERM_MULT VARCHAR(50),"
+ "PRIMARY KEY (EFFECTIVE_DATE, INTEREST_RATE_CD, INTEREST_RATE_TERM, INTEREST_RATE_TERM_MULT))";
The only difference is the Connection, either I take
con = DriverManager.getConnection("jdbc:h2:mem:ftp", "SA", "");
or
con = DriverManager.getConnection("jdbc:hsql:mem:ftp", "SA", "");
An often fired query for example is this one:
SELECT *
from INTEREST_RATES
where INTEREST_RATE_CD = ?
and EFFECTIVE_DATE = (SELECT MIN(EFFECTIVE_DATE)
from INTEREST_RATES
where INTEREST_RATE_CD = ?)
Now...
as for Hsql the application is finished within about 2 minutes.
as for H2 it's still not done after > 8 minutes.
What's wrong with my H2 setup? Seems like there are no indices created there, as Hsql does with help of the PRIMARY KEY ()? What else can be the problem?
Each DB engine has it's own implementation and in some scenarios can behave different.
I would try the following query, I think the index could be more efficiently used and returns the same result:
SELECT *
from INTEREST_RATES
where INTEREST_RATE_CD = ?
order by INTEREST_RATE_CD, EFFECTIVE_DATE
limit 1;
In the "order by" the first column is not really required as is already filtered but as explained here is needed so the PRIMARY KEY is correctly used by the engine in the execution plan.

Need to know Joomla Session timer data type

I have been looking under database of joomla. There I found under gu94g_session table, time column which is having value 1377499731. What does it mean. how I can decode this time. Would appreciate help.
The time column contains the Unix timestamp at the time of the records creation.
In Joomla! 2.5+ and 3.x+ the time column of #__session is set to value returned by PHP's time() i.e. the current Unix timestamp.
When sessions are stored in the database, the /libraries/joomla/sessions/storage/database.php file creates a record using this SQL query:
$query = $db->getQuery(true)
->update($db->quoteName('#__session'))
->set($db->quoteName('data') . ' = ' . $db->quote($data))
->set($db->quoteName('time') . ' = ' . $db->quote((int) time()))
->where($db->quoteName('session_id') . ' = ' . $db->quote($id));
The time is set with this line:
->set($db->quoteName('time') . ' = ' . $db->quote((int) time()))
Its time stamp value of the current date time.
When the user get logged in in the site front end or back end a corresponding session is created with their login time like strtotime(date("Y-m-d h:i:s")) and save that on the time column Then based on the back end value its check expiry and clear session.
I think now its clear for you..

A cleaner implementation rather than using LIKE

I have a table which contains Email Domains separated by semi-colons.
Domain
------
gmail.com;googlemail.com
hotmail.com;hotmail.co.uk;live.co.uk
I am currently running the following SQL:
SELECT [Id]
FROM [DomainGroup]
WHERE [Domain] LIKE '%' + (SELECT RIGHT('anemail#gmail.com', CHARINDEX('#', REVERSE('anemail#gmail.com')) - 1)) + '%'
Although this is working, I was thinking that maybe using PATINDEX would be better, from both performance and readability. The email address is actually a variable, but I've put it in to show what I'm trying to achieve.
I think the performance benefit of PATINDEX vs LIKE is at best ambiguous, particularly in your case given that normalizing the delimited values to individual rows in an indexed column would give more of a performance boost than anything else.
If you can't change design & want to use PATINDEX, then I would pre-compute the pattern;
declare #emaildomain varchar(128) = 'anemail#gmail.com'
set #emaildomain = '%;' + stuff(#emaildomain, 1, charindex('#', #emaildomain), '') + ';%'
Then use that in the where clause;
where patindex(#emaildomain, ';' + [Domain] + ';') > 0
(I padded with ; delimiters so aaa#bbb.com would not match aaabbb.com;)
Have you considered using fulltext search?
After creating the index, queries would look like:
SELECT [Id] FROM [DomainGroup] WHERE CONTAINS ([Domain], 'gmail.com')

How to get sets of Records in VB6?

Hey guys, just want to ask you a simple question that I know you're familiar with... I am using VB6, I just want to get sets of records from my database. What I mean is that I have UserID and with a part of code provided below, it only gets a single set of record. Like for instance, the value of UserID is A12, and so, all sets of records with the UserID of A12 must display in Textboxes respectively with the aid of datPayroll.Recordset.MoveNext.
With datPayroll
.RecordSource = "select * from tblpayroll where empid like '" & UserID & "'"
.Refresh
Me.txtRegularHours.Text = .Recordset.Fields!reghours
End With
-datPayroll : DataControl
-txtRegularHours : Textbox
-UserID : Variable
You probably want to look at MoveFirst, MoveNext, etc. and also EOF
Here is a link or two to get you started:
EOF, BOF
MoveFirst, MoveNext
You need to check that you have some data in your Recordset using EOF, then MoveFirst to move to the first record, and loop through using MoveNext.

Resources