Can we keep APEX open? Query works in SQL Developer but not Oracle APEX
Hi Sirini,
Just my thoughts -- but if one of these is closed, I think it should be the other one {thread:id=2496751} where he's getting the run-around. This one {thread:id=2496754} (APEX!) should be the one kept open. Don't you think?
My 2 cents,
Howard
..where he's getting the run-around...What runaround? The posters there determined that he needed a semi-colon at the end of the statement and then that he had forgotten the INTO clause. Both are beginner errors. OP has closed the thread as answered and has gone 'off to Google' to learn more about creating SQL queries in PL/SQL. This seems resolved -- at least until he comes back from his Googlequest with another question.
Similar Messages
-
Why will a query work in SQL Developer but not in Apex?
Here's a good one. I created a dynamic LOV with the following query.
select
e.DESCR d,
ee.ENTRD_EVNT_SK r
from
PT_EVNT_IN_DIV eid,
PT_ENTRD_EVNT ee,
PT_EVNT e
where ee.PGNT_SK = :PGNT_SK
and ee.CNTSNT_SK = :CNTSNT_SK
and ee.EVNT_IN_DIV_SK = eid.EVNT_IN_DIV_SK
and eid.EVNT_SK = e.EVNT_SK
and ee.ENTRD_EVNT_SK not in
(select js.ENTRD_EVNT_SK
from PT_JDG_SCR js
where js.JDG_SK = :JDG_SK
and js.PGNT_SK = :ai_pgnt_sk
and js.CNTSNT_SK = :CNTSNT_SK)
order by 1
The query works fine in SQL Developer, but Apex gives the following error when compiling it in the LOV editor.
"1 error has occurred
- LOV query is invalid, a display and a return value are needed, the column names need to be different. If your query contains an in-line query, the first FROM clause in the SQL statement must not belong to the in-line query."
I tried rearranging the entries in the From clause, but that didn't do any good.
Do you see what I can do to make Apex accept it?
Thanks,
KimKim
Kim2012 wrote:
select
e.DESCR d,
ee.ENTRD_EVNT_SK r
from
PT_EVNT_IN_DIV eid,
PT_ENTRD_EVNT ee,
PT_EVNT e
where ee.PGNT_SK = :PGNT_SK
and ee.CNTSNT_SK = :CNTSNT_SK
and ee.EVNT_IN_DIV_SK = eid.EVNT_IN_DIV_SK
and eid.EVNT_SK = e.EVNT_SK
and ee.ENTRD_EVNT_SK not in
(select js.ENTRD_EVNT_SK
from PT_JDG_SCR js
where js.JDG_SK = :JDG_SK
and js.PGNT_SK = :ai_pgnt_sk
and js.CNTSNT_SK = :CNTSNT_SK)
order by 1
The column named ENTRD_EVNT_SK is used twice in a select. Once in the main select and once in the inline query.
The validation maybe choking on that.
Try giving the column in the inline query an alias and see if that helps.
Nicolette -
Why does the query work in SQL Developer, but not in APEX?
Hi, guys:
I have a silly question. I have a complicated query, and I tested it successfully with SQL developer, and result is correct. However, when I put it into APEX to generate a report, it always reports no data found. I also know the condition related to "other marks" select list in the where clause part causes this problem. It also looks strange: before I add this condition, everything works OK; after I add this condition, even I do not choose the "other marks" select list, other components do not work neither. I always got no data found result. Could anyone help me on this problem? You can also visit our developing site as http://lsg-solutions.com:8888/apex/f?p=206 to check the problem.
Thanks a lot
Sam
select distinct 'MAP','Detail',so.doc_number as "DOC Number", so.offender_id as "Offender ID", so.first_name||' '|| so.middle_name||' '||so.last_name as "Offender Name",
so.date_of_birth as "Date of Birth",
(select sc1.description from sor_code sc1 where sc1.code_id=so.race) as "Race",
(select sc2.description from sor_code sc2 where sc2.code_id=so.sex) as "Sex",
(select sc8.description from sor_code sc8 where sc8.code_id=so.hair_color) as "Hair Color",
(select sc9.description from sor_code sc9 where sc9.code_id=so.eye_color) as "Eye Color",
replace(replace(nvl2(sl.address1, sl.address1||' '||sl.address2 ||' '||sl.city ||' '||sl.county||' '||(select sc3.description from sor_code sc3 where sc3.code_id=sl.state)||' '||sl.zip, 'No Known Address'),'#'),',') as "Address",
replace(replace(nvl2(sl.physical_address1,sl.physical_address1||' '||sl.physical_city ||' '||sl.physical_county||' '||(select sc4.description from sor_code sc4 where sc4.code_id=sl.physical_state)||' '||sl.physical_zip, 'No Known Address'),'#'),',') as "Physical Address",
sl.status as "Status",
sl.jurisdiction as "Jurisdiction",
to_char(sl.ADDRESS_LATITUDE) as "Address Latitude",to_char(sl.address_longitude) as "Address Longitude",
to_char(sl.physical_address_latitude) as "Physical Latitude",to_char(sl.physical_address_Longitude) as "Physical Longitude",
decode(rox.habitual, 'Y', 'Habitual', '') as "Habitual",
decode(rox.aggravated, 'Y', 'Aggravated', '') as "Aggravated",
rox.status as "Registration Status",
rox.registration_date as "Registration Date",
rox.end_registration_date as "End Registration Date"
from sor_location sl, sor_offender so, registration_offender_xref rox, sor_last_locn_v sllv
where rox.offender_id=so.offender_id
and sllv.offender_id(+)=so.offender_id
and sl.location_id(+)=sllv.location_id
and rox.status not in ('Merged')
and rox.reg_type_id=1
and upper(rox.status)='ACTIVE'
and nvl(rox.admin_validated, to_date(1,'J'))>=nvl(rox.entry_date, to_date(1,'J'))
and (((select sc11.description from sor_code sc11 where sc11.code_id=so.race and sc11.description=:P5_SL_RACE) is not null ) or (:P5_SL_RACE is null))
and (((select sc12.description from sor_code sc12 where sc12.code_id=so.sex and sc12.description=:P5_SL_SEX) is not null ) or (:P5_SL_SEX is null))
and (((select sc13.description from sor_code sc13 where sc13.code_id=so.hair_color and sc13.description=:P5_SL_HAIR_COLOR) is not null ) or (:P5_SL_HAIR_COLOR is null))
and (((select sc14.description from sor_code sc14 where sc14.code_id=so.eye_color and sc14.description=:P5_SL_EYE_COLOR) is not null ) or (:P5_SL_EYE_COLOR is null))
and (( so.offender_id in(select sm.offender_id from sor_code sc15, sor_mark sm, sor_offender so1 where sm.offender_id=so1.offender_id and sc15.code_id=sm.code and sc15.description=:P5_SL_OTHER_MARKS and sm.description is not null)) or (:P5_SL_OTHER_MARKS is null))My suggestion would be to put some instrumentation into your query and see what values you are using.. Or even simpler take out ALL the where clauses you can until data starts to sho wup and then add them back in one at a time until you find the culprit..
My bet would be on any date comparisons you are doing between page items and database columns..
Thank you,
Tony Miller
Dallas, TX -
Query works in SQL Developer but not in APEX
The query below runs fine in SQL Developer. I have tried entering it both as a Report Region based on SQL Query and in a Dynamic PL/SQL Region. I get different error messages in each. In the Dynamic PL/SQL Region I get the error that an INTO clause is expected in the select
statement. When I place it in a Report based on SQL query I get an error that there is an invalid column and to use column alias. What I am attempting to do is add the first query result to the second query result.
Select (select count(lead_id) from t3_leads
WHERE
t3_leads.market_id = 'Gurnee'
AND (T3_Leads.Last_Campaign = 'Hand Addressed' OR T3_Leads.Last_Campaign is null)
AND
((TRUNC(sysdate) - TRUNC(T3_Leads.LAST_MAILED_DATE)) > 60
OR T3_Leads.Last_Mailed_Date is null))
+
(select count(lead_id)from t3_leads where zip in (select zip from t3_overlap where t3_leads.zip = t3_overlap.zip)
and
market_id <> 'Gurnee'
and ((TRUNC(sysdate) - TRUNC(T3_Leads.LAST_MAILED_DATE)) > 60
OR T3_Leads.Last_Mailed_Date is null))
from dualHi,
you need a column alias for your "result" before the final 'from dual':
Select (select count(lead_id) from t3_leads
WHERE
t3_leads.market_id = 'Gurnee'
AND (T3_Leads.Last_Campaign = 'Hand Addressed' OR T3_Leads.Last_Campaign is null)
AND
((TRUNC(sysdate) - TRUNC(T3_Leads.LAST_MAILED_DATE)) > 60
OR T3_Leads.Last_Mailed_Date is null))
+
(select count(lead_id)from t3_leads where zip in (select zip from t3_overlap where t3_leads.zip = t3_overlap.zip)
and
market_id 'Gurnee'
and ((TRUNC(sysdate) - TRUNC(T3_Leads.LAST_MAILED_DATE)) > 60
OR T3_Leads.Last_Mailed_Date is null)) result
from dualPlease let me know if this works.
Thanks
Sandro -
Query works in SQL Developer but not in Oracle APEX
The query below runs and produces the correct result in SQL Developer, but when I try to put it into a PL/SQL process in Apex I get the error shown. There is no semi-colon at the end of the query in APEX.
The error is:
ORA-06550: line 10, column 54: PL/SQL: ORA-00933: SQL command not properly ended ORA-06550: line 2, column 1: PL/SQL: SQL Statement ignored ORA-06550: line 11, column 21: PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ( begin case declare end exception exit for goto if loop mod null pragma raise return select update while with.
The query is:
SELECT *
FROM
(SELECT *
from T3_LEADS
WHERE
(SYSDATE - Last_Mailed_Date) > 60 OR Last_Mailed_Date is null
WHERE MARKET_ID = 'Salt_Lake_City' AND rownum <= 100That is because when you run a SQL in SQL*Plus or SQLDeveloper the output is displayed on the screen, but in Apex you need to select those values into variables so you can do something with the data.
delcare
v_emp_id employee.emp_id%type;
begin
select emp_id
into v_emp_id
from employee
where lname = 'JOHNSON' and fname = 'BILLY';
-- Then do something with that data
if v_emp_id between 1 and 10 then
end if;
end;Probably a bad SQL for an example. For your SQL though, you are selecting * which you would be able to select into a rowtype variable, but you are probably going to start having problems like "Exact fetch returns more that one row" since your query will probably return more that one value. In those cases you want to use cursors, and loop through the data one record at a time. You can Google all of that. -
SQL Query works in SQL Developer, but not always in MII
Hi all,
I encountered a strange behaviour with a query in MII 12.0.2. Maybe someone has a guess what happens.
I have created a SQL query which runs against Oracle 10g tables. I have tested the query using SQL Developer, and it throws a couple of lines, depending on the contents of the where clause.
Next I have copied the query to a MII SQL Query (FixedQuery). However, the output is empty most of the time, without showing any errors. After some testing I got the impression that older data are not displayed, but there is no time or date setting in MII.
As the SQL Developer always returns rows, I am unsure where to search for the error.
Regards
MichaelMichael,
I would imagine that you have sub-select statements in your FixedQuery, all which will fall subject to the RowCount property of the query template (SQL defaults to 100), which is issued through the driver and typically honored by the database when returning the data from your request.
Most of the native database query tools allow you to make unbound query requests with no limit on rows, which would probably account for the difference between SQL Developer and the query template.
For SQLServer it's ROWCOUNT: http://msdn.microsoft.com/en-us/library/ms188774.aspx
For Oracle it's ROWNUM: http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
So the answer would be not to make the query template row count some rediculous number, but more appropriately refine the way that the database request is issued.
Regards,
Jeremy -
SQL works in SQL workshop but not in APEX
Hi All,
I'm trying some sample sql to get around the 32k limit in APEX and even though the sql works in SQLWorkshop, when I use it as a source for textarea object in APEX I get an error. Here's the SQL:
declare
l_code clob := empty_clob;
l_clob_source2 clob;
offset int:=1;
begin
select replace("CHNL_PRTNR_XML_TRAN"."XML_TRAN", '<', '<') into l_code from "CHNL_PRTNR_XML_TRAN" where "CHNL_PRTNR_XML_TRAN"."VITRIA_DROP_OFF_SEQ_ID" = :P2_TRAN_ID;
loop
l_clob_source2 := dbms_lob.substr(l_code,4000,offset);
htp.prn(l_clob_source2);
exit when offset + 4000 >= nvl(dbms_lob.getlength (l_code),0);
offset := offset + 4000;
end loop;
end;
Here's the error message I get APEX:
ORA-06550: line 13, column 17: PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ; The symbol ";" was substituted for "end-of-file" to continue.
Error ERR-1019 Error computing item default value: page=2 name=P2_XMLTRAN.Try to set it to SQL Query (PL/SQL-Functions Body), then it should work
-
SQL script works in SQL Developer but not when scheduled
I have a script that I can run, logged onto my server as a user with full permissions and into my database as SYSDBA, that produces a CSV file on the server when I run it from SQL Developer ON the server. HOWEVER, when I set it up as a scheduled job, using those SAME CREDENTIALS (same Windows/network user; same database user), I get no output. The job indicates that it's running successfully, but no file gets created.
Any advice is greatly appreciated.
Here's the script:
WHENEVER SQLERROR EXIT FAILURE;
set serveroutput on
DECLARE
my_query varchar2(5000);
BEGIN
my_query := q'[
SELECT client_id, JOB_NAME, SCHEDULE_TYPE, TO_CHAR(START_DATE,'MM/DD/YYYY HH24:MM') AS START_DATE,
REPEAT_INTERVAL, ENABLED, STATE, RUN_COUNT,
TO_CHAR(LAST_START_DATE,'MM/DD/YYYY HH24:MM') AS LAST_START, LAST_RUN_DURATION,
TO_CHAR(NEXT_RUN_DATE,'MM/DD/YYYY HH24:MM') AS NEXT_RUN
FROM DBA_SCHEDULER_JOBS
WHERE instr(client_id,'10.') is not null
ORDER BY LAST_START_DATE DESC
p2k.ccsd_any_query_to_csv('HRISEDB_E_OUTPUT_MK', 'dbserver_job_output.csv',my_query);
end;
=================================================================
Here's the called procedure (I don't really understand it -- I gleaned it from others on the internet):
-- DDL for Procedure CCSD_ANY_QUERY_TO_CSV
set define off;
CREATE OR REPLACE PROCEDURE "CCSD_ANY_QUERY_TO_CSV" (p_dir in varchar2, p_filename in varchar2, p_query in varchar2) AUTHID CURRENT_USER
is
l_output utl_file.file_type;
l_theCursor integer default dbms_sql.open_cursor;
l_columnValue varchar2(4000);
l_status integer;
l_query long;
l_colCnt number := 0;
l_separator varchar2(1);
l_col_desc dbms_sql.desc_tab;
l_col_type varchar2(30);
l_datevar varchar2(8);
BEGIN
l_query := 'SELECT SYSDATE FROM DUAL; ';
dbms_sql.parse(l_theCursor, p_query, dbms_sql.native);
dbms_sql.describe_columns(l_theCursor, l_colCnt, l_col_desc);
l_output := utl_file.fopen( p_dir, p_filename, 'w' );
dbms_sql.parse( l_theCursor, p_query, dbms_sql.native );
for i in 1..l_col_desc.count LOOP
utl_file.put( l_output, l_separator || '"' || l_col_desc(i).col_name || '"' );
dbms_sql.define_column( l_theCursor, i, l_columnValue, 4000 );
l_separator := ',';
end loop;
utl_file.new_line( l_output );
l_status := dbms_sql.execute(l_theCursor);
while ( dbms_sql.fetch_rows(l_theCursor) > 0 ) loop
l_separator := '';
for i in 1 .. l_colCnt loop
dbms_sql.column_value( l_theCursor, i, l_columnValue );
utl_file.put( l_output, l_separator || '"' || l_columnValue || '"');
l_separator := ',';
end loop;
utl_file.new_line( l_output );
end loop;
dbms_sql.close_cursor(l_theCursor);
utl_file.fclose( l_output );
execute immediate 'alter session set nls_date_format=''dd-MON-yy'' ';
exception
when others then
execute immediate 'alter session set nls_date_format=''dd-MON-yy'' ';
raise;
end;
/hello,
does oracle showing any errors in user_scheduler_job_run_details for this job ? I would advise try inserting some debug statement to identify where exactly its stuck. Also please check sample configurations syntax for user_scheduler_jobs.
Cheers
Sush -
Form auto query works in 10g developer, but not when served by forms server
I have a form with a master and two detail blocks on the same canvas. When I run it from the developer tool on my desktop, it works great, the master block populates as expected based on the GO_BLOCK and EXECUTE_QUERY statements, and the detail blocks both populate automatically, firing their POST_QUERY triggers as well. When I run it on the server, I have to execute query manually, and then navigate to each of the detail blocks and then execute their queries manually too. When I do that, their POST_QUERY triggers are not firing.
Desktop is (Windows XP Professional version 5.1 build 2600.xpsp_sp3_gdr.100427-1636 : Service Pack 3)
Developer version is Forms [32 Bit] Version 10.1.2.0.2 (Production)
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Oracle Toolkit Version 10.1.2.0.2 (Production)
PL/SQL Version 10.1.0.4.2 (Production)
Oracle Procedure Builder V10.1.2.0.2 - Production
PL/SQL Editor (c) WinMain Software (www.winmain.com), v1.0 (Production)
Oracle Query Builder 10.1.2.0.2 - Production
Oracle Virtual Graphics System Version 10.1.2.0.2 (Production)
Oracle Tools GUI Utilities Version 10.1.2.0.2 (Production)
Oracle Multimedia Version 10.1.2.0.2 (Production)
Oracle Tools Integration Version 10.1.2.0.2 (Production)
Oracle Tools Common Area Version 10.1.2.0.2
Oracle CORE 10.1.0.4.0 Production
Server version is OAS forms/reports install – 10.1.2.3
OS – x86-64bit (Red Hat Enterprise Linux Server release 5.4)hello,
does oracle showing any errors in user_scheduler_job_run_details for this job ? I would advise try inserting some debug statement to identify where exactly its stuck. Also please check sample configurations syntax for user_scheduler_jobs.
Cheers
Sush -
Generate DDL works in old version of SQL Developer, but not in new versions
Hello all,
How to generate DDL in new versions of Oracle SQL Developer for production Oracle database?
For production database, the generate DDL feature works fine in old versions (version 1.5.5) of Oracle SQL Developer, SQuirrel, Toad and many other similar tools, but not the new versions of Oracle SQL Developer (such as 2.1.1.64.45).
The SQL tab for a table is blank for me in production databases. Of course, it works fine in development Oracle database.
I did some research that many articles describe SELECT_CATALOG_ROLE as the required read-only role in production database. Our DBA did a test to grant me this role temporarily, and it worked for me to generate DDL using new Oracle SQL Developer. It is pain for me to ask for this role.
Is there a plug-in or work-around, so the new versions of Oracle SQL Developer can have this generate DDL feature in production without the mentioned SELECT_CATALOG_ROLE?
I could not find the answer in older forum threads.
For now, I will have to install older versions of Oracle SQL Developer.
ThanksI've seen a couple posts about people not being able to generate DDL for other users. To date, I've never seen a anybody post a workaround, nor have I seen one of the developers post a response, nor have I seen anybody say they've submitted a SR.
I think I remember reading somewhere that the new version of SQL Developer uses dbms_metadata.get_ddl to generate DDLS, rather than some custom query built on top of catalog views...which could explain why it use to work, but no longer does. But whether or not this is true, I don't know.
You could try submitting a SR and see if Oracle responds saying that it's a known bug and will be fixed in the next release. Until then, unless you get the role, you're stuck using something else for DDL generation. -
Query returns record in SQL Developer but not in iSQLPlus
... back in a minute, I may not have done a commit at the end of the insert.
The problem I was having was I hadnt commited the record in SQL Developer but the queries where returning records in this environment but not in iSQLPlus or Apex and it was confusing me.
Message was edited by:
Benton
Message was edited by:
BentonFinally got to know the reason why Timezone Abbr woudn't show up in SQL Plus.
I ran below query in SQL PLUS
SELECT SESSIONTIMEZONE, CURRENT_TIMESTAMP, systimestamp, LOCALTIMESTAMP FROM DUAL;
SESSIONTIMEZONE CURRENT_TIMESTAMP SYSTIMESTAMP LOCALTIMESTAMP
-05:00 08-SEP-12 12.00.31.575228 AM -05:00 08-SEP-12 12.00.31.575223 AM -05:00 08-SEP-12 12.00.31.575228 AM
Now executed the same query in SQL Developer:
SESSIONTIMEZONE CURRENT_TIMESTAMP SYSTIMESTAMP LOCALTIMESTAMP
America/Chicago 08-SEP-12 12.08.32.072424000 AM AMERICA/CHICAGO 08-SEP-12 12.08.32.072420000 AM -05:00 08-SEP-12 12.08.32.072424000 AM
The difference between the 2 outputs is the way in which time_zones were respresented. In SQL PLUS, it is shown as an offset whereas in SQL Developer as a time zone region name. Now there are many "time sone regions" that follow an offset of -5:00. This confuses Oracle and a "UNK"(Unknown) for a query like the one below when trying to execute in SQL PLUS:
select extract(timezone_abbr from from_tz(cast(sysdate as timestamp),SESSIONTIMEZONE)) from dual;
EXTRACT(TI
UNK
Therefore we need to specify the exact Time Zone Region(TZR) in order to obtain the corresponding TZD(Daylight Savings Format i.e. CDT or CST). This we do by altering the session environment vaiable time_zone
alter session set time_zone='America/Chicago';
Now executing the queries to find the abbreviated time zone( in TZD format) will finally work to return a non-null char value.
select extract(timezone_abbr from from_tz(cast(sysdate as timestamp),SESSIONTIMEZONE)) from dual;
EXTRACT(TI
CDT
select to_char(CURRENT_TIMESTAMP, 'TZD') from dual;
TO_CHA
CDT -
Query works in DB GUI, but not in CF
Hello,
I keep getting a CF error of "invalid character" for the
attached query.
Detailed error message: [Macromedia][Oracle JDBC
Driver][Oracle]ORA-00911: invalid character
I realize that's an Oracle error code, but the query works in
an Oracle db GUI (Toad).
Has anyone experienced this kind of situation?
Thank you.I've never tried using DDL in a CFQUERY myself with an Oracle
db, but you might try putting the entire statement inline (as in a
single line), rather than breaking it out like you did. It would be
hard to read, but it might parse better....... just a thought. I've
had similar problems with EXECUTE statements within a CFQUERY that
worked just fine when I rewrote them with no line breaks, etc.
Phil -
SQL query works in access 2000 but not through JDBC
Hello to all as my first posted message, I have a bit of a pickle on my hands. I have a query which is critical to for my application to function.
In Access 2000
SELECT sb.SeatName
FROM SeatBooking sb, Movie m, MovieSession ms, Booking b
WHERE m.MovieId = ms.MovieId
AND ms.MovieSessionId = b.MovieSessionId
AND b.BookingId = sb.BookingId
AND ms.DateOfSession = #2003/04/16 07:15:00 PM#;
This query works fine. When I insert it into my code
String query = "SELECT sb.SeatName \n" +
"FROM SeatBooking sb, Movie m, MovieSession ms, Booking b \n" +
"WHERE m.MovieId = ms.MovieId \n" +
"AND ms.MovieSessionId = b.MovieSessionId \n" +
"AND b.BookingId = sb.BookingId \n" +
"AND ms.DateOfSession = #" +
cp.getMovieSessionAt(i).getTrueTimeOfSession() + "#;";
The last line of code returns #2003/04/16 07:15:00 PM#; Which is the exact same as in Access.
To rule out some possibilities
- there are other less complicated queries which access the same database but work fine. so my code seems to be ok
- I have tried to use Format() on ms.DateOfSession to match the return value of the java statement (Which is a general date in Access in the format of 16/04/2003 7:15:00 PM)
Any suggestions would be appreciated!Hi Simon,
On my Windows XP system with J2SE SDK version 1.4.1_02 and Micro$oft Access 2002, I have the following table:
column name column type
id Number
name Text
updated Date/TimeUsing the JDBC-ODBC bridge driver (that is part of the J2SE distribution), the following code uses the JDBC "escape" syntax -- and it works.
import java.sql.*;
public class JdbcOdbc {
public static void main(String[] args) {
Connection dbConn = null;
ResultSet rs = null;
Statement stmt = null;
String sql =
"SELECT * FROM Table1 WHERE updated = {ts '2003-04-13 07:53:23'}";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dbConn = DriverManager.getConnection("jdbc:odbc:db1");
stmt = dbConn.createStatement();
rs = stmt.executeQuery(sql);
if (rs.next()) {
System.out.println("id = " + rs.getInt(1));
System.out.println("name = " + rs.getString(2));
System.out.println("updated = " + rs.getTimestamp(3));
catch (SQLException sqlEx) {
System.err.println("Database operation failed.");
sqlEx.printStackTrace();
catch (ClassNotFoundException cnfEx) {
System.err.println("JDBC driver class not found");
cnfEx.printStackTrace();
finally {
if (rs != null) {
try {
rs.close();
catch (SQLException sqlEx) {
System.err.println("ERROR: Failed to close result set");
sqlEx.printStackTrace();
if (stmt != null) {
try {
stmt.close();
catch (SQLException sqlEx) {
System.err.println("ERROR: Failed to close statement");
sqlEx.printStackTrace();
if (dbConn != null) {
try {
dbConn.close();
catch (SQLException sqlEx) {
System.err.println("ERROR: Failed to close DB connection");
sqlEx.printStackTrace();
}More details about the JDBC escape syntax are available here:
http://java.sun.com/j2se/1.4.1/docs/guide/jdbc/getstart/statement.html#999472
Hope this helps you.
Good Luck,
Avi. -
Cursor query works in anonymous block but not in procedure
Hello,
My cursor query works fine in anonymous blcok but fails in pl/sql block.
Anonymous block:
declare
cursor c1 is
select object_name
from all_objects
where owner='IRIS_DATA'
and object_type='SEQUENCE';
v_string varchar2(2000);
begin
for c2 in c1 loop
v_string := 'DROP SEQUENCE IRIS_DATA.'||c2.object_name;
execute immediate v_string;
end loop;
commit;
exception
when others then
dbms_output.put_line('Exception :'||sqlerrm);
end;
works fine.
but inside the procedure the it doesn't go inside the cursor loop
procedure get_sequence is
l_dp_handle NUMBER;
v_job_state varchar2(4000);
l_last_job_state VARCHAR2(30) := 'UNDEFINED';
l_job_state VARCHAR2(30) := 'UNDEFINED';
l_sts KU$_STATUS;
v_logs ku$_LogEntry;
v_row PLS_INTEGER;
v_string1 varchar2(2000);
cursor seq_obj is
select object_name
from all_objects
where owner='IRIS_DATA'
and object_type='SEQUENCE';
begin
log_status('get_sequence started.');
--Cursor records to drop the sequences before importing.
for seq_obj_rec in seq_obj loop
log_status('get_sequence: Dropping sequence started.');
v_string1 := 'DROP SEQUENCE IRIS_DATA.'||seq_obj_rec.object_name;
execute immediate v_string1;
end loop;
log_status('get_sequence: Dropping sequence completed.');
exception
WHEN OTHERS THEN
log_status('get_sequence: exception.');
end get_sequence;
it's not going into the seq_obj_rec cursor.
I granted select on all_objects to the user.this user is also having the DBA role as well.
Please advice.PROCEDURE Get_sequence
IS
l_dp_handle NUMBER;
v_job_state VARCHAR2(4000);
l_last_job_state VARCHAR2(30) := 'UNDEFINED';
l_job_state VARCHAR2(30) := 'UNDEFINED';
l_sts KU$_STATUS;
v_logs KU$_LOGENTRY;
v_row PLS_INTEGER;
v_string1 VARCHAR2(2000);
CURSOR seq_obj IS
SELECT object_name
FROM all_objects
WHERE owner = 'IRIS_DATA'
AND object_type = 'SEQUENCE';
BEGIN
Log_status('get_sequence started.');
--Cursor records to drop the sequences before importing.
FOR seq_obj_rec IN seq_obj LOOP
Log_status('get_sequence: Dropping sequence started.');
v_string1 := 'DROP SEQUENCE IRIS_DATA.'
||seq_obj_rec.object_name;
EXECUTE IMMEDIATE v_string1;
END LOOP;
Log_status('get_sequence: Dropping sequence completed.');
EXCEPTION
WHEN OTHERS THEN
Log_status('get_sequence: exception.');
END get_sequence; How do I ask a question on the forums?
SQL and PL/SQL FAQ
scroll down to #9 & use tags in the future. -
Query working fine in toad but not in forms 6i
i have following coding on when button press triger
declare
CURSOR C1(year number,month number) IS
SELECT ITM_NO,ITM_NAME,XAQ QTY,XAQ*TP VAL,gp
FROM
select ci.itm_no ITM_NO,ci.itm_name ITM_NAME ,cpg.group_id gp ,xaq ,ALLIED.CORP_PRIC_TP( ci.itm_no)TP from
select prod_no,sum(xaq)*1 xaq
from
select prod_no, sum(nvl(xrd_sqty,0)) Xaq
from allied.mrk_01_02
where year=year and f_prd=month
and area_id in (10200,10400,10100,10300,10500,20500,20300,20100,20200,20400,30100,30400,30300,30200)
group by prod_no
union all
select prod_no, sum(nvl(xrd_sqty,0)) Xaq
from allied.mrk_02_02
where year=year and f_prd=month
and area_id in (10200,10400,10100,10300,10500,20500,20300,20100,20200,20400,30100,30400,30300,30200)
group by prod_no
union all
select prod_no, sum(nvl(xrd_sqty,0)) Xaq
from allied.mrk_03_02
where year=year and f_prd=month
and area_id in (10200,10400,10100,10300,10500,20500,20300,20100,20200,20400,30100,30400,30300,30200)
group by prod_no
union all
select prod_no, sum(nvl(xrd_sqty,0)) Xaq
from allied.mrk_04_02
where year=year and f_prd=month
and area_id in (10200,10400,10100,10300,10500,20500,20300,20100,20200,20400,30100,30400,30300,30200)
group by prod_no
group by prod_no
) A,allied.corp_inv ci,allied.corp_01_01 c01, allied.corp_01_02 c02,allied.corp_prod_group cpg,allied.v_prod_grp vpg
where ci.itm_no=a.prod_no
and ci.itm_no=c02.itm_no
and c01.grp_id=c02.grp_id
and c01.grp_id in(55,56,57,58,59)
and vpg.prod_no =ci.itm_no
and vpg.group_id=cpg.group_id
where XAQ <>0;
Begin
delete from fiaz.tmp_topten_prod;
for i in c1(:year,:month)
loop
insert into fiaz.tmp_topten_prod
values(i.itm_no,i.itm_name,i.qty,i.val,i.gp,0);
end loop;
standard.commit;
message('inserted in temp');
exception when others then
message (dbms_error_text);
message (dbms_error_text);
End;
Same Query (as used in cursor c1) works fine in toad but giving wrong result from forms... and the problem is xaq field i.e returns incorrect qty...
i guess union clause is not working in this situation...
plz suggest me the appropriate changes in the query to work well from form as well...
combination:Forms 6i,Oracle 8.0.6
Regards,
Usman AfzalAs per your suggestion i have created a stored procedure but the followin error prevents procedure creation
create or replace procedure fiaz.topten_prod(v_yr number,v_mn number) is
begin
delete from fiaz.tmp_topten_prod;
insert into fiaz.tmp_topten_prod(itm_no,itm_name,qty,val,grp_id,prority)
SELECT ITM_NO,ITM_NAME,XAQ QTY,XAQ*TP VAL,gp,0
FROM
select ci.itm_no ITM_NO,ci.itm_name ITM_NAME ,cpg.group_id gp ,xaq ,ALLIED.CORP_PRIC_TP( ci.itm_no)TP from
select prod_no,sum(xaq) xaq
from
select prod_no, sum(nvl(xrd_sqty,0)) Xaq from allied.mrk_01_02
where year=v_yr and f_prd=v_mn
and area_id in (10200,10400,10100,10300,10500,20500,20300,20100,20200,20400,30100,30400,30300,30200)
group by prod_no
union all
select prod_no, sum(nvl(xrd_sqty,0)) Xaq
from allied.mrk_02_02
where year=v_yr and f_prd=v_mn
and area_id in (10200,10400,10100,10300,10500,20500,20300,20100,20200,20400,30100,30400,30300,30200)
group by prod_no
union all
select prod_no, sum(nvl(xrd_sqty,0)) Xaq
from allied.mrk_03_02
where year=v_yr and f_prd=v_mn
and area_id in (10200,10400,10100,10300,10500,20500,20300,20100,20200,20400,30100,30400,30300,30200)
group by prod_no
union all
select prod_no, sum(nvl(xrd_sqty,0)) Xaq
from allied.mrk_04_02
where year=v_yr and f_prd=v_mn
and area_id in (10200,10400,10100,10300,10500,20500,20300,20100,20200,20400,30100,30400,30300,30200)
group by prod_no
group by prod_no
) A,allied.corp_inv ci,allied.corp_01_01 c01, allied.corp_01_02 c02,allied.corp_prod_group cpg,allied.v_prod_grp vpg
where ci.itm_no=a.prod_no
and ci.itm_no=c02.itm_no
and c01.grp_id=c02.grp_id
and c01.grp_id in(55,56,57,58,59)
and vpg.prod_no =ci.itm_no
and vpg.group_id=cpg.group_id
where XAQ <>0;
commit;
end;
Error:
"PLS-00201: identifier ALLIED.MRK_01_02 must be declared "
i have not changed any thing in query working fine in toad without create procedure text and if i describe this table it shows the structure (desc allied.mrk_01_02)
Now where is the problemmmmm
Plz Help
Maybe you are looking for
-
Building a adf rich client component dynamically...
Is it possible to specify the af:selectItem(s) in a af:selctOneChoice using af|forEach where the "items" attribute" calls a client side List or Array? Where can I find for documentation regarding EL expressions and how to call a client side varible i
-
ITunes won't re-install in the correct drive
We recently "cleansed" our computer, and in the process ended up deleting most of the music library. We then tried to re-install iTunes into a new hardrive with a lot more space, which appeared to be successful. However, when importing songs back int
-
ESC key not working outside PS in Vista...
This haunts our users since we migrated to Vista. When Photoshop CS2/CS3 is running under Vista the ESCAPE key does not work correctly with other programs. When PS is running, the escape key works only when pressing SHIFT+ESC together. This is extrem
-
How to decrypt to get the message digest?
Ok, I'm aware that, message digest, is a one-way hash algorithm. From what I gathered, we can decrypt then use the MessageDigest method, IsEqual to compared the hash value to ensure they are the same right? But my problem is, right now, I has the cod
-
My new ipad gets hot, is this harmful? is there a way to avoid it?
My new ipad gets hot, is this harmful? is there a way to avoid it?