DQL script for using order by clause to get case insensitive values - dql

How to write a DQL script for getting the case insensitive string values using order by.
select *from country order by lower(name) giving me error. Thanks for your help in advance

Related

Can I loop over the results of an SQL query to use each value in another query all at once in SQL Developer?

What I want to achieve (if it is possible from SQL Developer) is that when I execute the script it do the following:
Run a SELECT statement that will return a list of IDs. Approx 270 records.
I need to use each of those IDs individually in another SELECT statement (in the WHERE clause) which will return some records. A few of this could result in over 17,000 records and some can be one.
Then each result from the second SELECT I want it to be exported to an excel or csv file into a folder at my pc.
I have both 'Select' ready but I don't know how to loop over the results of the first to grab each ID and use it in the second one. Also I don't know how to export automatically from the code.
You can use GROUP BY clause.
read more here:
http://docs.oracle.com/javadb/10.6.2.1/ref/rrefsqlj32654.html
If the first SELECT returns you IDs only, and that's all you need for your second SELECT, just use IN clause providing your first SELECT query for the second one.
Example:
-- Your second select
SELECT
col1
,col2
,col3
,col4
FROM
second_table
WHERE
some_foreign_id IN (
-- Your first select
SELECT
id
FROM
first_table
WHERE
some_conditions...
)
In my opinion don't use PLSQL for this. In PLSQL the only way you can get an output of this by using a REFCURSOR (unless you dont use UTIL File package to do it). A simple SELECT WITH JOIN condition will suffice your requirement.
Test illustration
SELECT A.* FROM TABLE_A A, TABLE_B
WHERE A.COMMON_COLUMN = B.COMMON_COLUMN;
Hope this helped you in same way

how to use Queryresult variable as input in other query in robot framework

I am doing 1 simple db connection test in Robot framework.I am doing as following-
${queryResults1} Query <sql query>
now I want to use the value of ${queryResults1} as input to another query. I am doing
Execute Sql String select * from customer where customer_id=${queryResults1}
here I am getting error .Execute Sql String doesnot get value of queryresult
how can I do this ?
thanks in Advance!!!
The problem is that your first query is returning a list of tuples -- a list of rows, each of which is a tuple of columns. Even though you're apparently expecting a single value from a single column in a single row, the data is still in this format. You need to pull the value out of that list of tuples before passing it to your second query.
For example:
Execute Sql String select * from customer where customer_id=${queryResults1[0][0]}

sqlite - use a column field in a limit clause

using sqlite, I'm trying to run a query with a limit clause, but instead of specifying a literal I am trying to use a column. Sadly I am getting an 'no such column' error. Is there a way of achieving what I mean without writing an external program?
Example
select * from ep where code=2 limit code
You have to use a subquery:
SELECT * FROM ep WHERE code = 2 LIMIT (SELECT code FROM ep WHERE ...)
Please note that the subquery must return a single value (if it returns multiple records, only the first one is used).

Basic SQL count with LINQ

I have a trivial issue that I can't resolve. Currently our app uses Linq to retrieve data and get a basic integer value of the row count. I can't form a query that gives back a count without a 'select i'. I don't need the select, just the count(*) response. How do I do this? Below is a sample:
return (from io in db._Owners
where io.Id == Id && io.userId == userId
join i in db._Instances on io.Id equals i.Id **select i**).Count()
;
The select i is fine - it's not actually going to be fetching any data back to the client, because the Count() call will be translated into a Count(something) call at the SQL side.
When in doubt, look at the SQL that's being generated for your query, e.g. with the DataContext.Log property.
Using the LINQ query syntax requires a select statement. There's no way around that.
That being said, the statement will get transformed into a COUNT()-based query; the select i is there only to satisfy the expression system that underlies the LINQ query providers (otherwise the type of the expression would be unknown).
Including the select will not affect the performance here because the final query will get translated into SQL. At this point it will be optimized and will be like select (*) from ......

Convert linq query with having

i fail while converting this sql to linq...
hope anybody do it.
SELECT Max([PersonalNumber]+1)
FROM TestTable
GROUP BY CalYear
HAVING CalYear=Year(Now())
Thanks.
The HAVING clause is there to enable you to filter on the results of an AGGREGATE. In this instance you are filtering on the GROUP column which could just be filtered using a WHERE clause instead.
Therefore you do not need to produce a HAVING clause in LINQ. A simple WHERE clause will do the same.
check out here --> http://blogs.msdn.com/vbteam/archive/2007/12/18/converting-sql-to-linq-part-5-group-by-and-having-bill-horst.aspx
From TestTable in a
Group By CalYear
into CalYear = Year(Now())

Resources