I've got a query:
SELECT < column names >
INTO <#temp_table>
FROM < table >
WHERE < stuff >
It runs fine in dbVisualizer. However, running it in Oracle SQL Developer gives me the error "The executeQuery method must return a result set."
What is happening here, and how can I fix it in SQL Developer?
EDIT: In response to Tanner, I get the errors when I try the following things (tell me if something I try is invalid. I'm new to SQL):
This:
select * into #temp_table from status
produces this:
The executeQuery method must return a result set.
This:
select * into #temp_table from status;
select * from #temp_table;
produces this:
Invalid object name '#temp_table'.
And this:
select *
from(
select * into #temp_table from status)
produces this:
Incorrect syntax near the keyword 'into'.
I'm lost, ladies and gentledudes.
If you have a query like:
SELECT *
INTO #TEMP
FROM TABLE_A
That is simply creating and inserting data into a temp table.
What you need to do is return that temp table, so after you have run that code you need to do this:
SELECT *
FROM #TEMP
Related
I try to add quotes. But it did not work:
I'm using Postgres.
Here is my query in navicat which results in syntax errors:
WITH t1 AS
(
SELECT
*
FROM
"olympics_history"
)
Yes it works like this:
WITH t1 AS
(
SELECT
*
FROM
"olympics_history"
)
SELECT games
FROM t1
WHERE t1.season = 'Summer'
Thanks #a_horse_with_no_name
I have ORDS 21 installed in a local 19c oracle database. I have created a stored procedure to list all the departments from the dept table with a cursor that lists the employees from the emp table. If I just list all departments and their employees the api works fine, but if I add a parameter to the query to specify which department, I get an error 17410 no data left .
Both queries are backed by plsql stored procedures. I have created many stored procedures using this same format with parameters and nested cursors before without a problem.
MWE for query that works:
create or replace procedure get_dept
as
l_cur sys_refcursor;
begin
open l_cur for
select d.deptno,d.dname,
cursor (select e.empno,e.ename
from emp e
where e.deptno = d.deptno
order by e.deptno,e.empno
) as employees
from dept d
order by d.deptno;
-- return the resultset in json format
apex_json.open_object;
apex_json.write('emps',l_cur);
apex_json.close_object;
end get_dept;
/
MWE for query that does not work:
create or replace procedure get_dept1
(
p_dept_no in varchar2
) as
l_cur sys_refcursor;
begin
open l_cur for
select d.deptno,d.dname,
cursor (select e.empno,e.ename
from emp e
where e.deptno = d.deptno
order by e.deptno,e.empno
) as employees
from dept d
where d.deptno = to_number(p_dept_no)
order by d.deptno;
-- return the resultset in json format
apex_json.open_object;
apex_json.write('emps',l_cur);
apex_json.close_object;
end get_dept1;
/
I'm a really bad in sql , my query is
select * from car_wash where
(select ST_Within((select car_wash.lon_lat from car_wash),(select ST_Buffer(ST_GeomFromText('POINT(65.3 323.2)'),20)))) = true
AND car_wash.was_deleted=false;
But i know that it isn't correct because nested query can return more than 1 column, how to modify this query to use where clause
select *
from car_wash cw
where
ST_Within (
cw.lon_lat,
ST_Buffer(ST_GeomFromText('POINT(65.3 323.2)'),20)
)
AND
not car_wash.was_deleted
I don't use postgresql, but maybe something like this works:
select * from car_wash
where EXISTS (select ST_Within((select car_wash.lon_lat from car_wash),
(select ST_Buffer(ST_GeomFromText('POINT(65.3 323.2)'),20))) within
WHERE within = true)
AND car_wash.was_deleted=false;
If it doesn't work, I have a variant, so tell me when.
I am trying to get a table based on the rootpage number/tbl_name and store in a custom TableObject.
I am able to get the table name by the root page number/tbl_name, but I have no idea about getting the row values from that table.
Here is what I have:
SELECT * FROM sqlite_master WHERE name='test1';
or
SELECT * FROM sqlite_master WHERE rootpage=4;
This thing gives me a row which has a table .
Now how can I get the test1 contents ?
The test1 table have two rows in it, called age and name. How can I access those columns ?
At the end I end up using the cursor, so the query will be something like:
cursor=db.rawQuery("SELECT * FROM sqlite_master WHERE rootpage = '" + rootNumber + "'",null);
I can use
cursor.getString(getColumnIndex("name")) //w.r.t sqlite_master
cursor.getString(getColumnIndex("rootpage")) //w.r.t sqlite_master
How can I use the same cursor to get something like:
cursor.getString(getColumnIndex("age")) //w.r.t test1
cursor.getString(getColumnIndex("name")) //w.r.t test1
to get the values from the resulted table.
I would suggest you that once you query sqlite_master table using cursor A, don't use the same cursor A as it contains result of the that query result.
Hence you need to fire another query and store the next result in another cursor B so that you don't lose the data from your first query.
For example, for master table,you do something like :
Cursor cursorA = db.rawQuery("SELECT * FROM sqlite_master WHERE rootpage = '" + rootNumber + "'",null);
cursorA.moveToFirst();
String tableName = cursorA.getString(getColumnIndex("name"));
For further getting result from the table "test1" that you got result from the previous query, you can do something like this :
Cursor cursorB = db.rawQuery("SELECT * FROM '" + tableName + "'",null);
cursorB.moveToFirst();
String name= cursorB.getString(getColumnIndex("name")) ;
int age= cursorB.getString(getColumnIndex("age")) ;
Hence you will get the result that you need further from table "test1".
Hope this helps you :)
I have a database in postgreSQL. I want to read some data from there, but I get an error (column anganridref does not exist) when I execute my command.
Here is my NpgsqlCommand:
cmd.CommandText = "select * from angebot,angebotstatus,anrede where anrid=anganridref and anstaid=anganstaidref";
and my 3 tables
the names of my columns are rights. So I don't understand why that error comes. Someone can explain me why it does crash? Its not the problem of large and lowercase.
You are not prefixing your column names in the where clause:
select *
from angebot,
angebotstatus,
anrede
where anrid = anganridref <-- missing tablenames for the columns
and anstaid = anganstaidre
It's also recommended to use an explicit JOIN instead of the old SQL 89 implicit join syntax:
select *
from angebot
join angebotstatus on angebot.aaaa = angebotstatus.bbbb
join anrede on angebot.aaaa = anrede.bbbb