Query on merge syntax
There is a syntax I don't understand in this procedure.
what is the :1) trip stands for in the bottom of the proc? notice it is for a trip_sec_num col in the table.
create or replace PROCEDURE "myProc" IS
count INT;
QRY_count INT;
today DATE;
trip NUMBER;
BEGIN
EXECUTE IMMEDIATE 'CREATE GLOBAL TEMPORARY TABLE temp_left
ON COMMIT PRESERVE ROWS
AS SELECT *
FROM personPEV
WHERE a <> ''666''
AND b IS NOT NULL ';
EXECUTE IMMEDIATE 'MERGE INTO hugetbl
USING (SELECT da_boy.c1,
da_boy.c2,
da_boy.IN_OUT_CODE
FROM da_parent
LEFT OUTER JOIN temp_left da_boy
ON da_parent.c1 = da_boy.c1
AND da_parent.c2 = da_boy.c2
WHEN NOT MATCHED THEN
INSERT (c1
c2,
IN_OUT_CODE,
trip_SEQ_NUM) <-???
VALUES (
temp_left.c1,
temp_left.c2,
temp_left.IN_OUT_CODE,
:1)' USING trip; <-???
This "using syntax" is part of "EXECUTE IMMEDIATE". Look at the :1 in you merge statement. The value of this bind variable will be assigned same as trip.
Here is some example of USING syntax. Please consult oracle documentation for more.
SQL> ed
Wrote file afiedt.buf
1 declare
2 procedure p1 (p_empno emp.empno%type) IS
3 v_name emp.ename%type;
4 begin
5 execute immediate 'SELECT ename from emp
6 where empno=:1' INTO v_name using p_empno;
7 dbms_output.put_line(v_name);
8 end;
9 begin
10 p1(7788);
11* end;
SQL> /
SCOTT
PL/SQL procedure successfully completed.By the way, it looks like that there is not much need to use dynamic SQL in your procedure, So Please consider it for rewriting. Unnecessary use of dynamic SQL is considered as bad practice.
Similar Messages
-
Dynamic SQL from within DML - merging syntax issue #2
Further to my previous thread on a SQL - DML merging syntax issue, I have another problem with multiple conditions in the WHERE-clause:
vrb _retval decimal
vrb _val1 text
vrb _val2 text
_val1 = 'value1'
_val2 = 'value2'
SQL SELECT DIM1_ATTR1 FROM MYSCHEMA.DIM1_DIM WHERE COL1 = :_val1, AND COL2 = :_val2, INTO :_retval
The above SQL will return NA. If I use the text literals instead of the OLAP variables, the query just runs fine. Also, with a single condition (on COL1 only) the query returns the expected value.
A note in the help states that OLAP DML objects should clearly be sperated from the rest of the SQL but does not say how. I am using a colon before and a comma after as without them the line would not compile. I could not find any example that would use multiple conditions in the WHERE-clause however the help text indicates that it is possible.
Please help me, how.
Regards,
Csaba
Windows, Oracle10gRel2 Ver. 10.2.0.1.0 eversion: 84090It does work, although I applied the finishing touch by removing the commas as well!
Thanks a lot! Good job!
Could you please have a look at issue #1 too? :-)
Regards,
Csaba -
Query Of Queries syntax error.
Hi all,
I have the following query:
<cfquery name="agent" datasource="datasourcename">
SELECT * FROM quotes where status = 'Pending'
<cfif isDefined("form.agent")>
AND agent = '#FORM.agent#'
</cfif>
</cfquery>
Then, I have the following query of that query
<cfquery name="totalvalue" dbtype="query">
SELECT SUM(value) as total FROM agent
</cfquery>
however I get the following error:
Query Of Queries syntax error.
Encountered "SUM ( value. Incorrect Select List,
on line 20 which is:
<cfquery name="totalvalue" dbtype="query">
now i'm sure this is identical to what ive used before but
getting the error. the totals query works fine when querying the
database direct, only got this error when I changed it to query the
master query.
i appreciate any help in advance, as no matter how much i
stare at it I can't see whats wrong!I believe that
value is a reserved word that is probably causing your
current error. I would rename this column, or alias it in your
original query. Also, I would add WHERE value IS NOT NULL to your
Q-of-Q to cover your NULLs.
Phil -
Bug in CF11 regarding Query of queries syntax?
So I have decided to try CF11 because of an official outstanding CF10 bug.
Once I installed CF11, I get an error when running code like this:
<cfquery name="LOCAL.stat_questions" datasource="#APPLICATION.dsn#">
SELECT survey_questionID
FROM tbl_survey_questions
</cfquery>
<cfset LOCAL.this_statID = 1>
<cfquery name="LOCAL.subset" dbtype="query">
SELECT survey_questionID
FROM [LOCAL].stat_questions
WHERE survey_questionID = <cfqueryparam cfsqltype="cf_sql_numeric" value="#LOCAL.this_statID#">
</cfquery>
The error I receive is: "Query Of Queries syntax error.
Encountered ";. "
If I remove the semi-colon... No error! Is this a bug, or was the semi-colon always bad, but just ignored?
ThanksI just always put it in out of habit from typing out actual MySQL queries (non QoQ). Never was a problem and I always did it. Now running CF11... it requires fixing. Thought it was strange.
I actually didn't even notice that the semi-colons weren't required in QoQ until I ran into this CF11 bug. I also notice the semi-colon isn't necessary for a MySQL query either in cfquery! Seems weird that it accepts them, but isn't required. Just ignores them? -
Session keeps running when the query has a syntax error
I have a weird scenario.
Take this query for example: select distinct physassignednum from hsi.docdeficiency where delinqlevel> 0 and dfcystatus in (1,6));
This query has a syntax error as there is an additional bracket at the end. I know that. When I run it on STJOSE database the session keeps running and never returns. Even if I stop it, it does not. I try to disconnect, it says "Connection is currently busy. Try again?" This behavior is pretty consistent on STJOSET. If I run this query on UMASS database it gives me this error (as expected)
ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
*Cause:
*Action:
Error at Line: 1 Column: 99
I do not know what is wrong with the STJOSE database connection that causes the session to hang and never return.
Please help.
-Nags
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production (both databases)
SQL Developer Version 3.0.04 Build Main-04.34This does not happen in sql*plus. It does not hang. It returns a proper error message.
HSI@stjose> select distinct physassignednum from hsi.docdeficiency where delinqlevel> 0 and dfcystatus in (1,6));
select distinct physassignednum from hsi.docdeficiency where delinqlevel> 0 and dfcystatus in (1,6))
ERROR at line 1:
ORA-00933: SQL command not properly ended
HSI@stjose> -
Use plan from stored_outlines from query with different syntax?
Hello,
I'd like to know is there any ability to use via stored_outlines plan from query with different syntax?
Database version - 11.1.06
If yes, maybe you'll take a look at steps (based on Metalink 726802.1), what I tried to do to make it work (with no success):
alter session set create_stored_outlines=good;
run good query
create private outline good from SYS_OUTLINE_0... -< GOOD
alter session set create_stored_outlines=bad;
run bad query
create private outline good from SYS_OUTLINE_0... -< BAD
update ol$ set sql_text, textlen, signature, hash_value, hash_value2 from BAD to GOOD records
leave ol$hintcount for GOOD untouched
delete ol$ where ol_name='BAD';
delete ol$hints where ol_name='BAD';
delete ol$nodes where ol_name='BAD';
execute dbms_outln_edit.refresh_private_outline('GOOD');
alter session set sql_trace=true;
alter session set use_private_outlines=true;
run bad query
examine trace file and find that it use execution plan different from both bad and good queries
PS: Originally bad query is posted already Re: Poor performance while join of 2 comprehensive large views and small table
PPS: Also I review thread CBO not picking correct indexes or doing Full Scans
Thanks,
Sergiy
Edited by: kiberpress on Sep 30, 2009 6:59 AMA query with different syntax would result in a different hash value.
Stored outlines work based on hash value.
Your question is probably answered now.
Sybrand Bakker
Senior Oracle DBA -
Need a query to merge output in a single row?
Hi All,
I need a query to merge output in a single row.
Query :
Select dname from dept.
Actual output is :
Dname
EDP
ACCOUNT
GR
Desired Output is:
Dname
EDP ACCOUNT GR
Please provide me the solution
Thanks
Amitselect max(sys_connect_by_path (t.name,' ')) from ( select id,
name,
group_id,
row_number() over (partition by group_id order by id) rn
from ( select 1 id, 'test' name, 1 group_id from dual
union
select 2 id, 'test1' name, 1 group_id from dual
union
select 3 id, 'test2' name, 1 group_id from dual
union
select 4 id, 'test3' name, 1 group_id from dual) ) t
start with t.rn = 1 and id = 1
connect by t.rn = prior t.rn + 1
group by t.group_id -
Query code cotains Syntax Errors
Hello Experts,
In the process of upgrading from 4.6 to 6.0 ECC SAP version, we had some issues at the moment of testing Queries from SQ01 transaction, nevertheless almost all the problems with queries were solved by regenerating them all over again from SQ01 for Queries and SQ02 for Infosets.
Everything was OK so far, until I tested this Query related to PCH Logical Database and realized that It had Syntax Errors and can't run, and the other 5 Queries related to the same Logical Database are having the same Syntax Errors and they can not be fixed by executing the Query from SQ01 or regenerating the Infoset (PCHORG) from SQ02.
I guess the Syntax Errors must be fixed by regenerating the code in the new version, but how can I do this?
Or, is there another process I am skipping to achieve this?
Any ideas on this?
Thanks in advance!Hello VitorDFPinheiro thanks for your answer,
I tried to modify the errors manually but in first Instance this is not possible whitout an Access Key and secondly I think this is not the best practice due the code for queries is generated Automaticaly.
Nevertheless I tried to correct this syntax errors by copying the code and pasted it into a new Z program and compile it, the compiler threw even more errors when I corrected the first one, so I think that this is not the way to procced.
I guess that there should be a way to "regenerate" the query and this "regeneration" must reorganize the code and its syntax.
Any other suggestions?
Edited by: memo_cv on Oct 11, 2010 6:56 PM -
Warning in query in Extended Syntax Check
Hi all,
I perform Extended Syntax Check.
It generates following warning for the query: -
In "SELECT SINGLE....", the WHERE condition for the key field "MATNR" does not test for equality. Therefore the single record in question may not be unique.
(You can hide the message using "#EC *)
Please tell me what does it mean. How can I suppress this warning?
Regards,
Saurabh A. BukshHi,
whenu r using select single use a variable or a workarea don't use tables.
select single matnr from mara into v_matnr
where matnr in s_matnr.
also as it is warning message u can neglectit .
when u r using select single u should give entire key information also.
Regards,
Nagaraj
Message was edited by: nagaraj kumar nishtala -
Second call of an SQL query throws a syntax error?
Private Sub RefreshDataSet()
Dim strSQL As String = DataAdapter1.SelectCommand.CommandText
Try
DataSet1.Clear()
DataAdapter1.SelectCommand.CommandText() = Trim(strSQL & " WHERE BadgeID = " & strEmployeeBadge)
DataAdapter1.Fill(DataSet1)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
When I call the above procedure, the sub does work correctly and I get the expected results / records in the dataset. But, when I call the Sub again (to refresh the dataset) it gives me an "incorrect syntax" error.
I'm not sure why it is doing this. Any suggestions or ideas?Youjun,
It's very frustrating when you keep asking if the code is the same, or if I have tested the code. I've said that I debugged.. I've said I have tested the code. Your continuing to ask me this is pointless, rude, and only serves to make YOU look
stupid. I'm sorry if that is rude, but please stop asking me!
To respond:
I supposed that the original DataAdapter1.SelectCommand.CommandText is "select * from table1"
-Yes, the base command is similar to this, except that I call each database field, not using the *.
1) When you run it the first time, the DataAdapter1.SelectCommand.CommandText will be "select * from table1 WHERE BadgeID ='123'".
-Yes, I append 'WHERE BadgeID = XXX' to the query, the first and
each subsequent time. Again, I said that the code/call/syntax DOES NOT CHANGE. It is the
same every time.
2) Then you changed the strEmployeeBadge, I supposed that is '234'
-NO! I do NOT change the code!! I'm sorry, but what part of 'the query is
exactly the same' is unclear?
3) when you run it next time, the DataAdapter1.SelectCommand.CommandText will change to "select * from table1 WHERE BadgeID ='123'
WHERE BadgeID = '234'"
-NO! I have specifically tested for this
and as stated, the SQL syntax does not change!
So it 'syntax' fail will pop out when second call.
-NO, your assumptions are INCORRECT.
I suggest you recording the commandText when first change the DataAdapter1.
I write a testing program for you.
-Your 'testing program' is for all purposes, the same exact code as what I used. There is no difference.
Now, as also stated before, I have several other instances
where I use the same 'technique' to amend the base SQL queries of the DataAdapter. Each of these other instances work fine, and I use them to 'refresh' my DataSet information several times throughout the running of my program. Just for some
reason, this time, it does not work. I don't know why and was hoping someone else had found the same/similar issue and also found a resolution. The DataAdapter is configured the same as the others, the code is the same as well. I will just
have to find a work around, or other way to do what I want I guess.
Lastly, yes, I set strSQL in the subroutine because I want that variable to be gone at the end of the procedure. It recalls, then sets the syntax, every time the Sub is called on purpose. I do not want strSQL to be 'global', which by the way,
according to Microsoft documentation I have read, is no longer possible. Global variables are 'technically' not used/recognized anymore. If this has changed, then I stand corrected.
Thank you for responding, I will just find another solution I guess. -
Simple query ... syntax error ?
What is wrong with this simple sql statement ?
SELECT Caseid
FROM (SELECT DISTINCT Caseid, userid FROM Atts)
I get this error
Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near ')'.In this case, it could go either way. Because the derived
table is
performing the select distinct anyway, the execution plans
would be similar,
but you'd see one extra step for selecting all rows from the
derived table.
Notice that the derived table has distinct caseid, userid,
but the main
query only selects caseid. If the extra IO required to
transmit the
unwanted userid column is more expensive than the extra step
required to
select just the caseid column out of the derived table, then
the derived
table is the better choice.
In any case, the simpler query is usually the better option.
Unless he
actually wants a duplicate caseid for each userid, but not
the userid
itself, plain ol' SELECT DISTINCT makes more sense.
"bregent" <[email protected]> wrote in
message
news:ejaad1$k2u$[email protected]..
> >On the contrary, subqueries in the FROM clause are
quite useful and can
> >in
> >the right situations perform much better than
alternative queries.
>
> Ah, as usual you are correct. It looks like he forgot to
add a DT alias
> name
> at the end of the statement which is causing the error.
But in any case, a
> simple select distinct would yield the same results and
performance,
> correct?
> -
Hi,
I am getting dump when executing ABAP Query..
Error in the ABAP Application Program
The current ABAP program "AQL4LA==========ZTST_DATA=====" had to be terminated
because it has
come across a statement that unfortunately cannot be executed.
The following syntax error occurred in program "/1BCDWB/SAPLIQ000000000486 " in
include "/1BCDWB/LIQ000000000486$04 " in
line 5:
"A FUNCTION already exists with the name "/1BCDWB/IQ000000000486SSCR"."
Any help ?
GiriHello,
Please refer to SAP note 723577 and implement the recommendations within and regenerate the query.
Hope this helps.
Regards,
David -
Query of Qeries Syntax problem
I'm getting an error on the syntax for my SELECT statement in
a Query of Queries. The code is:
<cfquery name="OnOrderLogData" dbtype="Query"
result="result3">
SELECT *,
ROW_NUMBER() OVER([ORDER] [BY] RowNumber [ASC]) + 0 AS
PageOrder
FROM OOLogView
WHERE RowNumber > 3 AND RowNumber <= 33
</cfquery>
The error is:
Encountered "(. Incorrect Select Statement, Expecting a
'FROM', but encountered '(' instead, A select statement should have
a 'FROM' construct.
I know that certain reserved words need to be escaped with
square brackets, and I have surrounded all the words that were on
the list in the reference manual with square brackets. I did not
see anything in the reference manual that says I can not use
parenthesis in the SELECT statement, nor anything that says I can
not use the SQL function ROW_NUMBER. I have spent several hours
trying many different things and still can't get it to work. It
works fine when I execute it as an Ad Hoc query in SQL Server 2005
Studio Express (when I take out the square brackets).
Can anyone please help me figure out what is wrong and how to
fix it? Thanks.> Adam, your's was the least impolite
Heh. Talk about "damning with faint praise".
> I have Ben Forta's 3 volumes, the CF Reference Manual
and the CF User's Guide.
> None are very specific about what IS OK to do,
I actually find livedocs to be the best resource for looking
up CF stuff.
http://livedocs.adobe.com/coldfusion/8/using_recordsets_1.html
Or googling these forums (NB: *Google*, not the in-built
search function,
which is rubbish).
> If I would say something to my boss such as, "You
shouldn't expect..." or
> "What do you expect..." in the context as these answers,
I would be in the dog
> house.
Sure. But you're not our boss. If we were to draw parallels
like that,
it'd be the other way around if anything. (I would not draw
the parallels
either way, that said). I actually *would* talk to one of my
subordinates
like that, but I'm noted at work for my "terseness" at times
(some might
describe it in harsher terms than that ;-). We've all got
different
expectations, I guess.
> That is the kind of criteria used to judge the
appropriateness of how
> one should converse with other people.
OK, well I think - for the reasons you outlined - you're
going to be a bit
disappointed there. I recommend ignoring the tone (or at
least the tone
you're perceiving), and just take the info as given. On the
whole, people
here are pretty polite, actually.
But anyway. I think you got your answer, so job done.
Although now you've
got to work out another way of sorting out your issue...
Adam -
Alternative for result from other query and merge dimension option option
Hi Everyone ,
Am Developing one webi report over bex Query.
Actual scenario is output of one webi report should be the input of other webi report.
Eg:
Table 1
2010 Cus 1
2010 Cus 2
2011 Cus 3
table 2
cus1 m1 100
cus2 m2 200
Cus3 m1 400
Report 1 designing
First report created using table 1 and prompt for year
Report 2 designing
Second report created using table2 and prompt for customer
So when am Running first report it will ask for parameter year and if am selecting 2010 then the report will return C1 and C2
this out put should e the input for report 2.
So out put will be 100+200=300
NOTE:1. Result from other query is not working in webi filter pane since am building on olap universe.
2. Merge Dimension performance is very slow .
Any Solution ?
Regards,
Kannan.BHi,
Thanks for ur reply
As you said , If am giving hyperlink to other report .
Eg: User selected Tamilnadu then report 1 opened then he has to click the some cell or hyperlink cell to view the actual report(2nd report).
Suppose user Clicked that hyperlink cell and 2nd report opened and he is viewing the data for Tamil nadu and he decided to see the report for
Andrapradesh so according to this logic he has to select first report and refresh the data for Andra and from there he has to come to 2nd report.
totally 4 screen will be opened for seeing the two states report.
So Some other alternative....... -
Hi,
Could somebody please help with the C# syntax for Oracle Lite. I can execute select statement without parameters, but parameterized query doesnt work. What is wrong in my code?
LiteConnection liteConn=new LiteConnection("10270_pwcoffline");
LiteCommand lcmd=new LiteCommand() ;
lcmd.Connection=liteConn;
lcmd.CommandText="Select * from ol_off_dept where office = :off";
lcmd.CommandType=CommandType.Text ;
int off = 10;
LiteParameter p1 = new LiteParameter("off", DbType.VarNumeric, "office");
p1.Value = off;
lcmd.Parameters.Add(p1);
LiteDataAdapter lad=new LiteDataAdapter(lcmd);
DataSet ds=new DataSet();
lad.Fill(ds,"TDM");
this.dataGrid1.DataSource = ds;
The error is:
System.Data.DataException: 37000[POL-5228] syntax error at Oracle.Lite.Data.LiteCommand.Prepare()
ThanksJenny,
Please let us know if you still need this post resolved.
Thank you.
Maybe you are looking for
-
How to display the multiple rows in a single column ?
Hi, I have the Query like this : SELECT MS.SUBJECT, MS.MESSAGEDESC, MS.MSGDATE, MAT.ATTACHMENT FROM MESSAGES MS, MSESAGEATTACHEMTASSO MAA, (select pga.programid, act.accountname, row_number() over(partition by pga.programid order by act.accountname)
-
Does Adobe have actual support for their products?
Or does Adobe actually rely on these forums and/or for the customer figure things out for themselves? First issue is that all video playback within Premiere CS6 stopped working ( periodically it works for a few days then stops again) . After trying a
-
Is there a possibility to print the filename into the picture?
Is there a possibility to print the filenames into the picture or into the slideshow? When presenting photos to clients over Apple TV there must be a way to find the image name for ordering. Any ideas, I did not find anything!
-
Reschedule Exception message in MRP
Hi ALL. MRP suggests rescheduling a PO to create a new one for delivery in the past. The planner clicks the Processing Indicator (Dealt With). As soon as additional orders come in and change the quantity, the "Dealt with is over-ridden" Can this be p
-
Email -almost no 'real estate' on screen
new screen HORRIBLE.. Please give me back the top half of the screen. It's all wasted. PLEASE tell me how to spread the list of emails to the top of the screen. You don't need half the screen to say We're Verizon. I'm already a customer.. Just p