Comparintg times in a dynamic sql statement
I am working on a coversion procedure from one database to another. I have a move procedure that calls functions and the like .
I am trying to use dynamic sql and my where clause is giving me errors. What am I missing here ? TIA....
DEFINE DATECUTOFF ='11-JAN-05' of type date
DES_DATE is a date column in the 2nd database .... type date
I am building strings to do a create table from the 2nd database ...
Testwhere := q'[where to_char("des_date", 'DD-MM-YY') < '01-JAN-05]'; === works but I want to pass in date variable
Teststring := 'Create table '|| table_name || ' as select * from '|| second_table||'@'Linkname
execute immediate teststring || ''|| testwhere;
Testwhere := q'[where to_char("des_date", 'DD-MM_YY') < to_char(DATECUTOFF, 'DD-MON-YY')]; gives me errors like invalid number, or invalid type depending on where the quotes are or how I define DATECUTOFF
Any ideas of what I am doing wrong in comparing the two dates ?
Thanks.
Sorry if I confused anyone ... we're working a duo effort here and get confused ourselves. Here's a summary of the effort.
We're on 11G Linux.
We're writing scripts, procedures and functions that will help us transition from a remote database (Ingres) to oracle. We plan to do this for many dbs, so we are using variables for the table names, links, etc ....
The Where clase that we are developing is pretty
complex, so our initial attempts to build it is
to make it into two sections as a "literal" , join them and do a execute immediate. A date fields seem to be the issue...
Our main procedure calls a datamove function to do the select from the remote data base....
DATECUTOFF is date;
TESTWHERE is varchar2(600);
TESTSTRING varchar2(600);
TestString := 'Create table '|| table_name_temp|| as select * from '||remote_table_name||'@'Linkname;
TestWhere :=q'[ Where ||des_date < 'DATECUTOFF'];
execute immediate Teststring || '' ||Testwhere;
Can I do this in dynamic plsql ? the des_date is the column from the remote database. DATACUTOFF comes from the main procedure passed in.
I do a DBMS_OUTPUT.Put_Line{teststring);
DBMS_OUPUT.Put_Line(testwhere);
and get the following on my screen
Create Table AC_KEY_TEMP as select * from ACK_KEY2@DBLINK2
where "des_date" = 11-Jan-05
DECLARE
Error at line 1;
ORA-00904 "JAN" invalid identfier
ORA- 06512 at datamove.datamove, line 146
ORA-06512 at line 49, which is the line for
the TestWHERE string.
so in the procedure, if DBMS_OUTPUT is correct, the execute immediate is operating on the where clause and it
thinks the JAN field is incorrect. I have put single quotes around it as well ...
Similar Messages
-
How to control the maximum time that a dynamic sql can execute
Hi,
I want to restrict the maximum time that a dynamic sql can execute in a plsql block.
If the execution is not completed, the execution should be terminated and a exception should be raised.
Please let me know, if there is any provision for the same in Oracle 10g.
I was reading about Oracle Resource Database Resource Manager, which talks about restricting the maximum time of execution for Oracle session for a user.
However I am not sure, if this can be used to control the execution of dynamic sql in a plsql block.
Please provide some pointers.
Thank you,
Warm Regards,
Navin Srivastavanavsriva wrote:
We are building a messaging framework, which is used to send time sensitive messages to boundary system.I assume this means across application/database/server boundaries? Or is the message processing fully localised in the Oracle database instance?
Every message has a time to live. if the processing of message does not occurs within the specified time, we have to rollback this processing and mark the message in error state.This is a problematic requirement.. Time is not consistent ito data processing on any platform (except real-time ones). For example, messageFoo1 has a TTL (time to live) of 1 sec. It needs to read a number of rows from a table. The mere factor of whether those rows are cached in the database buffer cache, or still residing on disk, will play a major role in execution time. Physical I/O is significantly slower that logical I/O.
As a result, with the rows on disk, messageFoo1 exceeds the 1s TTL and fails. messageFoo2 is an identical message. It now finds most of the rows that were read by messageFoo1 in the buffer cache, enabling it to complete its processing under 1s.
What is the business logic behind the fact that given this approach, messageFoo1 failed, and the identical messageFoo2 succeeded? The only difference was physical versus logical I/O. How can that influence the business validation/requirement model?
If it does, then you need to look instead at a real-time operating system and server platform. Not Windows/Linux/Unix/etc. Not Oracle/SQL-Server/DB2/etc.
TTL is also not time based in other s/w layers and processing. Take for example the traceroute and ping commands for the Internet Protocol (IP) stack. These commands send an ICMP (Internet Control Message Protocol) packet.
This packet is constructed with a TTL value too. When TTL is exceeded, the packet expires and the sender receives a notification packet to that regard.
However, this TTL is not time based, but "+hop+" based. Each server's IP stack that receives an ICMP packet as it is routed through the network, subtracts 1 from the TTL and the forwards the packet (with the new TTL value). When a server's IP stack sees that TTL is zero, it does not forward the packet (with a -1 TTL), but instead responds back to the sender with an ICMP packet informing the sender that the packet's TTL has expired.
As you can see, this is a very sensible and practical implementation of TTL. Imagine now that this is time based.. and the complexities that will be involved for the IP stack s/w to deal with it in that format.
Making exact response/execution times part of the actual functional business requirements need to be carefully considered.. as this is very unusual and typically only found in solutions implemented in real-time systems. -
Preparing Dynamic SQL statement for inserting in Pro*C
Hi Friends,
From quite some time i am struggling writing Dynamic SQL statement for dynamic insert and update in Pro*C.
Can somebody go through my code and suggest me the rigth way of doing.
Right now it throws an error saying " Error while updating ORA-00904: invalid column name "
Please help me.
Girish.
int main()
EXEC SQL BEGIN DECLARE SECTION;
char *uid ="scott/tiger";
static char sqlstmt[129];
struct /* DEPT record */
int dept_num;
char dept_name[15];
char location[14];
} dept_rec;
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER SQLERROR DO sql_error();
EXEC SQL CONNECT :uid;
dept_rec.dept_num = 50;
strcpy(dept_rec.dept_name,"ADMIN");
strcpy(dept_rec.location,"IN");
strcpy(sqlstmt,"UPDATE dept set DNAME = dept_rec.dept_name where DEPTNO = dept_rec.dept_num");
EXEC SQL EXECUTE IMMEDIATE:sqlstmt;
EXEC SQL COMMIT;
exit(0);
void sql_error()
printf("\nError while updating %s",sqlca.sqlerrm.sqlerrmc);
EXEC SQL ROLLBACK;
}A bit rusty here but this is how I see it.
Think of it this way ..
all Oracle is going to see is:
UPDATE dept set DNAME = dept_rec.dept_name where DEPTNO = dept_rec.dept_num
Its NOT going to know what dept_rec.dept_name is or dept_rec.dept_num is ..
it doesnt go back and fill in those values.
You need something like
strcpy(sqlstmt,"UPDATE dept set DNAME = \"");
strcat(sqlstmt,dept_rec.dept_name);
strcat(sqlstmt,"\" where DEPTNO = ");
strcat(sqlstmt,dept_rec.dept_num);
printf(sqlsmt); # Just to be sure the update statement look right during testing. -
How can I execute Dynamic SQL statement in Forms?
Hi All,
I have to execute dynamic SQL statement from Forms
Below statement I have to execute
"EXECUTE IMMEDIATE v_stmt INTO v_return;".
Googled for the same got results saying, Better use Database function or procedures to execute these Dynamic Statements but We want to execute in forms only.
Can any one help me..
Thanks,
MadhuSo in short you are trading code obfuscation for maintainability and the ability to share code between tools? If from somewhere else you need a procedure already implemented in database PL/SQL (and now ported to forms) this would mean you'd need to implement it in every other tool. In times where you might want to integrate your forms with $other_technology and putting stuff on the database is the first step to share functionality you just go the opposite way? And all that because someone is afraid that somebody might steal your source code? I am sorry to be blunt, but this is just plain stupid.
Leaving aside that some things like Analytic Functions, Bulk processing or execute immediate are not even available in forms your software consists of how many LOC? How long does it take to bring a new developer up to speed with your source code? Imagine how long that would take for a developer who doesn't have coleagues who know their way around.
And just so you know: I work for a ISV selling a closed-source product as well. We have 200+ customers all over the planet. We are well aware that wrapped packages can be reverse engineered. The premise is: stored procedures can be reused in every tool we have, if it makes sense to put stuff on the database by all means do it. If someone would want to reverse engineer our software I'd wish him good luck as some parts are implemented in such a hilarious complicated way I have troubles understanding them (and quite frankly I refuse to understand certain parts, but that's another story). I do work for almost 10 years for that ISV.
In any case the possible solutions have already been mentioned: you have exec_sql, create_group_from_query and forms_ddl to execute dynamic SQL in forms whereas forms_ddl is a one way street and most certainly not the thing you need or want. Take a look at the documentation for the other 2 things.
cheers -
How can I open a cursor for dynamic sql statement
Hi,
I'm facing issues opening a cursor for dynamic sql statement : PLS-00455: cursor 'RESULT1' cannot be used in dynamic SQL OPEN statement.
CREATE OR REPLACE FUNCTION DEMO
(MN_I in VARCHAR)
return AB_OWNER.ABC_Type.NonCurTyp is
RESULT1 AB_OWNER.ABC_Type.NonCurTyp;
sql_stmt VARCHAR2(4000);
BEGIN
sql_stmt := 'SELECT * FROM AB_OWNER.DUN WHERE JZ_I in ('||mn_i||') ORDER BY app.ACC_I';
OPEN RESULT1 FOR sql_stmt;
END IF;
return RESULT1;
END DEMO;
What changes should I make in the code so that it doesn't fail? I can't change the definition of RESULT1 cursor though.Gangadhar Reddy wrote:
I used SYS REFCURSOR and was able to implement successfully.How many times did you run this successful implementation that does not use bind variables?
Because this is what will happen when it runs a lot.
http://download.oracle.com/docs/cd/E11882_01/server.112/e17766/e2100.htm#sthref1874
http://forums.oracle.com/forums/search.jspa?q=%2BORA-04031%20%2Bbind&objID=c84&dateRange=all&rankBy=10001&start=30
And you will have to regularly restart the server, or possibly slightly less invasive, flush the shared pool.
Flushing Shared Pool regularly
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1516005546092
>
Ok, this is an easy one to diagnose.
You are not using bind variables. This is terrible. Flushing the shared pool is a bad
solution -- you are literally killing the performance on your box by not using them.
If I was to write a book on how to build non scalable applications in Oracle, this
would be the first and last chapter. This is a major cause of performance issues and a
major inhibitor of scalability in Oracle. The way the Oracle shared pool (a very
important shared memory data structure) operates is predicated on developers using bind
variables. If you want to make Oracle run slowly, even grind to a total halt just
refuse to use them.
>
But, please feel free to go ahead with this successful implementation.
I just hope anyone else who reads this doesn't make the same mistake. -
How to get the time for executing an SQL statement?
hi all...
How can I get the total execution time for a given SQL statement to a ViewObject which is created dynamically for this SQL so that the end user knows it before hand and try to stop it or go further..?
Please post any ideas if you have got..!!!
thanx in advance..
grüss
K°viThis is not really a question for the JDeveloper forum, but rather for the DB forum.
Since Oracle9i there is a way to estimate how long a query will take, before executing it.
Check it out in the Oracle DB documentation or ask on the DB forum.
There is no built-in functionality for this in JDeveloper, but you should be able to call out to the DB from your Java code to get the estimate. -
Help With SUBSTR in dynamic SQL statement
Following is the dynamic SQL statement.
EXECUTE IMMEDIATE 'UPDATE table_name pml
SET pml.'|| con_fields.field ||' = SUBSTR(pml.'||con_fields.field||' ||'' ''||
(SELECT pml1.'||con_fields.field||'
FROM table_name pml1
WHERE pml1.grp_id = '||los_concats.grp_id ||'
AND pml1.row_id = '||los_concats.row_id||'
AND pml1.loser_flg = ''Y''),1, '||con_fields.max_length||')
WHERE pml.grp_id = '||los_concats.grp_id ||'
AND pml.loser_flg IS NULL ';
what it does is that it updates a particular field. This field is concatenated by a field of a similar record.
My problem is with SUBSTR function. Since I am concatenating fields I do not want the field to be updated greater than max_length on that field, the reason why I use SUBSTR. the select query inside SUBSTR works alright with one of the AND condition in a WHERE clause not present. When I add that additional condition it gives me this error.
ORA-00907: missing right parenthesis.
Is there any way to get around this problem. Does SQL has other than SUBSTR function which can limit the character length.
Appreciate it.The other alternative I thought about was to do this first
EXECUTE IMMEDIATE 'SELECT pml.'||con_fields.field||'
FROM table_name pml
WHERE pml.grp_id = '||los_concats.grp_id||'
AND pml.row_id = '||los_concats.row_id||'
AND pml.loser_flg = ''Y''
' INTO v_concat_field;
write into the variable v_concat_field and then use it into the previous script.
But on this I get SQL Command not properly terminated, I don't get it Why?
Donald I tried with your suggested script. It works fine with one of the conditions eliminated. I don't understand what the error trying to say?
Thanks -
Concatenate problem for Dynamic SQL statements
Hi Experts ,
I am building Dynamic SQL statements depending on the values which the user enters into the select option parameters .This dynamic query is passed to cl_sql_connection object for querying from another databasse
So i wrote dynamic values for one select option spointof for the database field ppointofdelivery.
loop at spointof.
CONCATENATE ' pointofdelivery between ''' spointof-low''''
' AND ''' spointof-high''''
INTO where_clause .
endloop.
The whereclause has value pointofdelivery between '123' and '124'.(if the user has entered 123 and 124 as values)
This works fine . But my problem is I have to pass the fieldnames and operator dynamically into where_clause depending on User input.
when i am writing code like the below
field_name = ' pointofdelivery '.
operator = '='.
CONCATENATE field_name operator '''spointof-low''' INTO where_clause .
the where_clause contains value
pointofdelivery = ' spointof-low '
and not pointofdelivery = ' 123 ' as expected .
Do you know why this is haapening as it is not taking the value.
Thanks
ArshadHi,
there are lot of function modules..available...to build a where clause based on the select-options..
check the FM FREE_SELECTIONS_RANGE_2_WHERE
Thanks
Naren -
Dynamic SQL statement in a Procedure
Hi,
is it possible to use a variable in place of a column name in a sql statement inside a procedure. Or to create the whole statement as a sql statement and execute it (preferrably with parameters - rather than concatinating the values).
Thanks for any help or direction
ElliotTurns out you can do the following very nicely (dynamic sql with parameterized values)
Declare
id number(10,0);
sql_stmt varchar2(300);
fieldName varchar2(30);
fieldValue varchar2(100);
id := 30;
fieldName := 'somecolumn';
fieldValue := 'some value';
sql_stmt := 'UPDATE myTable SET ' || fieldName || ' = :1 WHERE id = :2';
EXECUTE IMMEDIATE sql_stmt USING fieldValue, id; -
Execute Dynamic SQL statement using procedure builder
i want to execute a dynamic SQL statment using procedure builder not using forms
because my statement depending on a variable table name
i know that i can do that from forms using
FORMS_DDL('SQL_STAT');
but i wanna to use the procedure builder
which function i should use and how?
please explain in example if you don't mind.
thanksHi,
You can very well use DBMS_SQL Package supplied by Oracle for doing this.
Search for DBMS_SQL in OTN. You will get all info regarding this.
Regards.
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by itslul:
i want to execute a dynamic SQL statment using procedure builder not using forms
because my statement depending on a variable table name
i know that i can do that from forms using
FORMS_DDL('SQL_STAT');
but i wanna to use the procedure builder
which function i should use and how?
please explain in example if you don't mind.
thanks<HR></BLOCKQUOTE>
null -
Dynamic SQL Statement with table name
Dear all
i like to have a SQL statement with a dynamic tablename. Is this possible? If yes, how?
should be something like "select * from <mytablename>"
Thank you
HerbertYes this is possible. use the below reference code for this.
data: g_tablename type w_tabname,
gv_dref TYPE REF TO data.
FIELD-SYMBOLS: <g_itab> TYPE STANDARD TABLE.
gv_tabname = p_tablename (take table name form selection screen or as per ur requirement)
CREATE DATA gv_dref TYPE TABLE OF (g_tabname).
ASSIGN gv_dref->* TO <g_itab>.
now use the below select query to fetch the data
SELECT * FROM (gv_tabname) INTO TABLE <g_itab>.
Hope this will help -
Hi
Here is an interesting question for all. My application has to support 5 markets. For that I created a report based on querying a view. That report is based on some search criteria which comes through a form. Right now the report is perfectly working as I have queried it as
select * from portland.rsu_inventory where ne = :ne_no
But we have some more markets apart from PORTLAND. For that we want to use the same application. So we have to be able to pass the market name dynamically. I am able to capture the market name in the search croteria form. But how can I send the market name to the Report SQL statement like
select * from | |MarketName| |.rsu_inventory where ne = :ne_no
Here the "MarketName" should be the market name that I would dynamically pass.
How can I acieve this. Thanks for any kind of suggession.
venuAccording to the metalink, the new version of OracleAs Portal is no longer support the query statement passing to this wwv_render_report.show procedure but however you can pass the cursor handle to this procedure instead. Here is the sample code to call this procedure:
declare
v_qry_stmt varchar2(32767) ;
v_cur_hdl int;
begin
v_cur_hdl := dbms_sql.open_cursor; -- open cursor
v_qry_stmt := '<your query>';
--Example query:
--v_qry_stmt := 'select empno,ename from scott.emp';
dbms_sql.parse(v_cur_hdl, v_qry_stmt, dbms_sql.native);
PORTAL30.wwv_render_report.show(p_table_border=>'1',
p_heading_bgcolor=>'#FFFFF0',
p_heading_font_face=>'Arial',
p_heading_font_size=>'13',
p_table_bgcolor=>'#FFFFFF',
p_font_face=>'Arial',
p_font_size=>'10',
p_query=>to_char(v_cur_hdl),
p_col_headings=>PORTAL30.wwv_standard_util.string_to_table2('Employee Number:Employee Name')
end;
Thanks
-Krishnamurthy -
Time of execution of SQL statement
Hi,
I executed some DML statements and Select statements as user SYS for user U1. How can I find the time of execution of these statements?
Regards,
MathewYou have a couple of options to time queries.
SET TIMING ON has already been mentioned. I'll add that spooling the session to a file helps keep those timings for later reference.
You can use DBMS_UTILITY.GET_TIME to get start and end times in microseconds for PL/SQL evaluation. DBMS_PROFILER will time lines of PL/SQL code as they execute. Trace/tkprof has also already been mentioned, although tkrpof times tend to vary a bit between reported and real times and don't take OS activity into account as much as the other timings do. -
Creating a dynamic sql statement
hi,
I am having a query
select w.id, w.cr_dt, w.cc_cor_addr_id, w.cc_cee_addr_id,
w.ttl_pkgs, w.chrg_wt, wf.wb_bkg_chgd_amt + wf.wb_bkg_chgd_amt_st
from ops_waybl_fin wf, ops_waybl w
where wf.id = w.id
and cre_bill_batch_dtls_id in (select get_bill_batch(1) from dual);
the bold part is a function returns a select query.
if the sql statement is run then we get data based on which the parent query returns data.
how we should use a function that returns select query.
Please advice..*** not tested *** Sven probably had in mind something like
with
v_count_cust_no as
(select count(orr.param_val) the_count
from ops_report_req orr
where orr.id = :p_req_id
and orr.param_nm = 'CUST_ID'
v_count_cust_cntr as
(select count(orr.param_val) the_count
from ops_report_req orr
where orr.id = :p_req_id
and orr.param_nm = 'CUST_CNTR_ID'
variant as
(select case when (select the_count from v_count_cust_no) > 0
then case when (select the_count from v_count_cust_cntr) > 0
then 1
else 2
end
else case when (select the_count from v_count_cust_cntr) > 0
then 3
else 4
end
end the_type
from dual
select w.id,w.cr_dt,w.cc_cor_addr_id,w.cc_cee_addr_id,w.ttl_pkgs,w.chrg_wt,wf.wb_bkg_chgd_amt + wf.wb_bkg_chgd_amt_st
from ops_waybl_fin wf,ops_waybl w
where wf.id = w.id
and cre_bill_batch_dtls_id in (select to_number(b.id)
from ops_bill_batch_dtls b,ops_cust_cntr cc
where b.cust_cntr_id = cc.id
and b.bill_batch_id = f1(1)
and b.status_lid = 255
and (((select the_type from variant) = 1
and cc.cust_no in (select param_val
from ops_report_req
where id = :p_req_id
and param_nm = 'CUST_ID'
and cc.ID in (select param_val
from ops_report_req
where id = :p_req_id
and param_nm = 'CUST_CNTR_ID'
or ((select the_type from variant) = 2
and cc.cust_no in (select param_val
from ops_report_req
where id = :p_req_id
and param_nm = 'CUST_ID'
or ((select the_type from variant) = 3
and cc.ID in (select param_val
from ops_report_req
where id = :p_req_id
and param_nm = 'CUST_CNTR_ID'
or ((select the_type from variant) = 4
) Regards
Etbin -
Dynamic SQL Statements with an JDBC Adapter
Hello,
i have a simple scenario:
A WebService calls SAP XI and XI has convert this request into an dynamic SQL for a particular DB-Table.
Two Questions:
1. Can this done with an JDBC-Receiverchannel or do i have to write a Java Server-Proxy?
2. How do i bring dynamic SQL Stratement into the JDBC Receiver-Adapter?
Regard
GunnarI think you should be able to achieve this using the SQL_QUERY / SQL_DML action in the JDB receiver adapter...
The SQL string can be dynamically created....
see the help link on different document types with JDBC receiver adapater....look for statement6...
http://help.sap.com/saphelp_nw04/helpdata/en/2e/96fd3f2d14e869e10000000a155106/frameset.htm
<StatementName6>
<anyName action= SQL_QUERY | SQL_DML>
<access>SQL-String with optional placeholder(s)</access>
<key>
<placeholder1>value1</placeholder1>
<placeholder2>value2<placeholder2>
</key>
</anyName >
</StatementName6>
Thanks,
Renjith
Maybe you are looking for
-
I've downloaded free trial versions of illustrator and photoshop but software not opening.Help!
-
How do we do conversion of customer deposits. In the functional spec what document type we need to provide to bring in the deposits. I dont see any document type for down payment. Do we use transaction code F-29 in place of F-22 or FB01 to bring in d
-
How to schedule an interface in ODI
Hi, I have created an interface which loads data into essbase. I need to schedule this interface so that the dataload runs periodically. How can i do it? I also need to configure mails as and when the dataload completes. Please suggest
-
WCEM Best Practice deployment in a multi CRM Landscape
Hi SCN Im looking for advice in relation to best practice deployment of WCEM. Specifically in a multi CRM landscape scenario. Do best practices exist? JR
-
When I open my browser and tap on any site listed in tiles It's not getting open doesn't matter how many times I am tapping.So I need to open it in a new tab.Is there any reason for that.?