Use of 'CAST' in SQL query
I am using following objects.
CREATE OR REPLACE TYPE t_assoc_agents_address AS OBJECT
(V_CONTACT_NAME VARCHAR2(120),
V_ADDRTYPE VARCHAR2(80),
V_ADDRESS_LINE1 VARCHAR2(50),
V_ADDRESS_LINE2 VARCHAR2(50),
V_ADDRESS_LINE3 VARCHAR2(50),
V_CITY_STATE_ZIP VARCHAR2(100),
V_PHONE VARCHAR2(50),
V_ADDRESS_FAX VARCHAR2(30),
V_ADDRESS_EMAIL VARCHAR2(80)
CREATE OR REPLACE TYPE nt_assoc_agents_address AS TABLE OF t_assoc_agents_address;
Following SQL query is working fine.
Sql:
SELECT *
FROM
table(cast (lv_assoc_agents_add_out AS nt_assoc_agents_address));
But, following Sql query doesn't work.
SELECT V_ADDRESS_FAX,V_ADDRESS_EMAIL
FROM
table(cast (lv_assoc_agents_add_out AS nt_assoc_agents_address));
Oracle Error: 'V_ADDRESS_EMAIL' invalid identifier.
Would you please clarify this, and suggest appropriate solution to select specific columns instead of
selecting all columns in above SQL query.
OK, I have found your code in your previous post.
It works in 9.2.0.1.0 and 8.1.7.0.0.
SQL> CREATE OR REPLACE TYPE t_assoc_agents_address AS OBJECT
2 (V_CONTACT_NAME VARCHAR2(120),
3 V_ADDRTYPE VARCHAR2(80),
4 V_ADDRESS_LINE1 VARCHAR2(50),
5 V_ADDRESS_LINE2 VARCHAR2(50),
6 V_ADDRESS_LINE3 VARCHAR2(50),
7 V_CITY_STATE_ZIP VARCHAR2(100),
8 V_PHONE VARCHAR2(50),
9 V_ADDRESS_FAX VARCHAR2(30),
10 V_ADDRESS_EMAIL VARCHAR2(80)
11 )
12 /
 
Type created.
 
SQL> CREATE OR REPLACE TYPE nt_assoc_agents_address AS TABLE OF t_assoc_agents_address
2 /
 
Type created.
 
SQL> var c refcursor
SQL> col v_address_fax format a15
SQL> col v_address_email format a15
SQL> declare
2 lv_assoc_agents_add_out nt_assoc_agents_address
3 := nt_assoc_agents_address(
4 t_assoc_agents_address(null,null,null,null,null,null,null,
5 'New Fax', 'New Mail')
6 );
7 begin
8 open :c for select V_ADDRESS_FAX,V_ADDRESS_EMAIL from
9 table(cast(lv_assoc_agents_add_out as nt_assoc_agents_address));
10 end;
11 /
 
PL/SQL procedure successfully completed.
 
SQL> print c
 
V_ADDRESS_FAX V_ADDRESS_EMAIL
New Fax New MailWhat is your Oracle release and how are you using ref cursor (if I interpret your example right) ?
Rgds.
Similar Messages
-
How to create a Matrix table using this data in SQL Query Analyzer
Hello all,
I have a problem while I am trying to represent my Sql Table namely table1 in Matrix form
my table Format is
city1 city2 Distance--------------------------------------------------------
Mumbai Delhi 100
Delhi Banaras 50
Mumbai Rajasthan 70
Banaras haryana 40
Mumbai Mumbai 0
784 entries
there are 784 cities each having link to other
Now i want my output as
Mumbai Delhi Banaras haryana
Mumbai 0 100 -- --
Delhi 100 0 50 --
Banaras
haryana
respective distance from one city to other should be shown
final Matrix would be 784*784
I am using SQL Query Analyser for this
Please help me in this regardI'm pretty much certain that you don't want to do this in pure SQL. So that means that you want to do it with a reporting tool. I'm not familiar with SQL Query Analyzer, but if it is in fact a reporting tool you'll want to consult its documentation looking for the terms "pivot" or perhaps "cross tab."
-
How can I use the Rownum/Customized SQL query in a Mapping?
Hi,
* I need to use a Rownum for populating one of the target field? How to create a mapping with Rownum?
* How can I use an Dual table in OWB mapping?
* Can I write Customized SQL query in OWB? How can I achieve this in a Mapping?
Thanks in Advance
KishanHi Niels,
As I'm sure you know, the conundrum is that Reports doesn't know how many total pages there will be in the report until it is all done formatting, which is too late for your needs. So, one classical solution to this problem is to run the report twice, storing the total number of pages in the database using a format trigger, and throwing away the output from the first run when you don't know the total number of pages.
Alternatively, you could define a report layout so that the number of pages in the output is completely predictable based upon, say, the number of rows in the main query. E.g., set a limit of one, two, ... rows per page, and then you'll know how many pages there will be simply because you can count the rows in a separate query.
Hope this helps...
regards,
Stewart -
Hi.
Why it doesn't work in the SQL Query of Crystal?
EXEC ('USE ZZZ_'+{?Base})
SELECT........................
{?Base} is a string variable and its value is correct
ThanksYou probably can't use an expression for EXEC. I know MS SQL doesn't allow it. However, you don't need an expression if this is in an SQL Command data source. Just use:
USE ZZZ_{?Base}
As long as {?Base} is a string parameter, its value will be substituted into the line - without quotes. So if the parameter value is AAA, the resulting line would be
USE ZZZ_AAA
You can do the same thing with field names or other SQL text. Obviously, you want to control the values that the parameter can be when you do such a thing... (Do not allow the user to type what will be used in unquoted SQL!)
HTH,
Carl -
Lookup creation and using this lookup in SQL query
I Have two tables one table called T_KEY_VALUES (KEY_ID , VALUE) and other is my transition table T_TRANSACTIONS (VERSION_ID , COL_VENDOR , COL_PREFIX, COL_RECIPTID , COL_STATE , COL_COUNTRY ..)
The data looks like below:
T_KEY_VALUES:
KEY_ID , VALUE,
10, CA
11, NY
13, NJ
20, USA
21, CANADA
101 , AMC
102, REGAL
1001, MOVIES
1002, MALLS
T_TRANSACTIONS:
VERSION_ID , COL_VENDOR , COL_PREFIX , COL_RECIPTID , COL_SATE , COL_COUNTRY
1, 101 , 1001 , 100001 , 10 , 20
2, 102 , 1002 , 100002 , 11 ,20
Generally, COL_VENDOR, COL_PREFIX , COL_STATE , COL_COUTRY field values exist in the T_KEY_VALUES table.
So How can I use T_KEY_VALUES as Lookup and write the one SQL query to get the data like below:
1, AMC , MOVIES , 100001 , CA ,USA
2, REGAL , MALLS , 100002 , NY , USAHi,
One way is to join t_transactions to 4 copies of t_key_values:
SELECT t.version_id
, v.value AS vendor
, p.value AS prefix
, t.col_reciptid
, s.value AS state
, c.value AS country
FROM t_transactions t
JOIN t_key_values v ON v.key_id = t.col_vendor
JOIN t_key_values p ON p.key_id = t.col_prefix
JOIN t_key_values s ON s.key_id = t.col_state -- or col_sate
JOIN t_key_values c ON c.key_id = t.col_country
If you'd care to post CREATE TABLE and INSERT statements for the sample data, then I could test this.
The query above assumes all 4 coded columns in t_transactions have matching values in t_key_values, as they do in the sample data. If that assumption is wrong, then use outer joins in some (or all) of the places where I used inner joins above.
Another approach is to UNPIVOT t_transactions into 4 times as many rows, do a single join to t_key_values, and then PIVOT those results back to the original number of rows. -
Ajax Autocomplete Tabular does not work using apex_item.text in SQL Query.
Hello,
Is it possible to use the search function which is used in, Dennis Kubicek example, ENAME topic Ajax Autocomplete Tabular
in a sql query using apex_items?
Query line :
, apex_item.text(17,xp.part_nr,null,null,'onfocus="f_register(this);" autocomplete="off"') PART
At first I followed the example by adding 'onfocus="f_register(this);" autocomplete="off" in the element attributes in the report field.
This didn't work... so tried to add the it in the attirbutes parameter of the apex_item.
But this still doesn't work. No errors are given, it does not respond.
Could somebody please help me?
Thx!
AstridWell, I'm trying to take this one step further, but I seem to be having some difficulty.
I'm trying to make a Filter screen to create a dynamic where clause filter screen.
This is a page I made with Popup LOVS, just to show you my goal (now trying to use autofilters)
http://apex.oracle.com/pls/otn/f?p=29989:5
I have a table on my system that tells you where the field is, and I'm using that to get the table (didn't want to change the javascript, so I pass in a static value).
This is the javascript code I used
<pre>
<script language="JavaScript" type="text/javascript">
function f_register(p_this,p_name)
var p_registered = $x('P5_ITEM_ID').value;
var p_this_name = $x(p_this).id;
//alert(p_this_name);
if (p_registered != p_this_name)
register(p_this_name, "COSTING_M", p_name, "blue", "red");
$x('P5_ITEM_ID').value = p_this_name;
</script>
</pre>
This is my query
<pre>
select column_name || apex_item.hidden(1,column_name) Col_name,
apex_item.SELECT_LIST_FROM_lov(2,'=','OPERATOR') OPERATOR,
apex_item.text (3,
NULL,
20,
200,
'onfocus="f_register(this,''' || column_name || ''');" autocomplete="off"',
'f3_' || '#ROWNUM#',
NULL
) value,column_id
from user_tab_cols
where table_name = 'COSTING_M'
ORDER BY ROWNUM
</pre>
and here is my on-demand process
<pre>
declare
TYPE CurTyp IS REF CURSOR;
v_row varchar2(4000);
rec CurTyp;
V_TABLENAME NKW.UTFIELD_M.TABLE_NAME%TYPE;
begin
BEGIN
SELECT TABLENAME INTO V_TABLENAME
FROM NKW.UTFIELD_M
WHERE FIELD_NAME = :TF_SL_COLUMN;
EXCEPTION WHEN NO_DATA_FOUND THEN RETURN; END;
:TF_SL_SEARCH := replace(:TF_SL_SEARCH, '&','&');
:TF_SL_SEARCH := replace(:TF_SL_SEARCH, '<','<');
:TF_SL_SEARCH := replace(:TF_SL_SEARCH, '>','>');
:TF_SL_SEARCH := replace(:TF_SL_SEARCH, '"','"');
owa_util.mime_header('text/xml', FALSE);
htp.p('Cache-Control: no-cache');
htp.p('Pragma: no-cache');
owa_util.http_header_close;
htp.prn('<rowset>');
open rec for
'select distinct ' || :TF_SL_COLUMN || ' ' ||
'from NKW.' || V_TABLE_NAME || ' ' ||
'where '||:TF_SL_COLUMN||' like :1||''%'' ' ||
'and rownum < 100 ' ||
'order by '||:TF_SL_COLUMN
using :TF_SL_SEARCH;
loop
fetch rec into v_row;
exit when rec%NOTFOUND;
htp.prn('<row>' || htf.escape_sc(v_row) || '</row>');
end loop;
htp.prn('</rowset>');
end;
</PRE>
I made some slight mods to make the table dynamic from my source table (this is to grab master files when they exist and not to when they don't).
I get my select list, but it's blank on all fields, any suggestions?
thanks,
Scott -
How to use Associative Array in sql query?
Hello,
I have a problem on using Associative Array variable on query; and my query is similar to the one below;
TYPE OTHERGENERICS IS TABLE OF NUMBER(10) INDEX BY BINARY_INTEGER;
othersGenerics OTHERGENERICS;
CURSOR cursor_othersGenerics IS
select master.GENERICCODEID
from ASMTRG_ARTICLEMASTER master
join ASMTRG_ARTICLEMAP map on MAP.ARTICLECODEID = MASTER.ID
group by MASTER.GENERICCODEID
minus
select FGG.GENERICCODEID
from asmtrg_icfocusgroup fg
join asmtrg_icfocusgrpchannel fgc on FGC.GROUPID = FG.ID and fgc.isactive=1
join asmtrg_icfocusgengroup fgg on FGG.GROUPID = FG.ID and FGg.ISACTIVE=1
where fgc.channelid=1 and fg.isactive = 1
group by FGG.GENERICCODEID;
BEGIN
OPEN cursor_othersGenerics;
FETCH cursor_othersGenerics BULK COLLECT INTO othersGenerics;
CLOSE cursor_othersGenerics;
SELECT icfrd.*,
CASE
WHEN EXISTS(select ta.genericcodeid from <???XXX???> ta where ta.genericcodeid = icfgrp.genericcodeid) THEN -1
ELSE icfrd.icfgroupid
END CLASSIFICATION
FROM ASMTRGVIW_ICFOCUSREPORTDATA icfrd
LEFT JOIN ASMTRG_ICFOCUSGROUP icfgrp on icfrd.ICFGROUPID = icfgrp.ID
WHERE (channelId IS NULL OR icfrd.CHANNELID = channelId)
AND (asmCodeId IS NULL OR icfrd.ASMCODEID = asmCodeId)
AND (yearId IS NULL OR icfrd.YEARID = yearId)
AND (monthId IS NULL OR icfrd.MONTHID = monthId)
END;
By the way this is a part of my function.
The "othersGenerics" is my associative array variable and <???XXX???> is the place where I need to use my "othersGenerics" array to check. So far I've tried
"select ta.genericcodeid from table(cast(otherGenerics as OTHERGENERICS)) ta where ta.genericcodeid = icfgrp.genericcodeid",
"select ta.genericcodeid from table(otherGenerics) ta where ta.genericcodeid = icfgrp.genericcodeid",
"select ta.genericcodeid from otherGenerics ta where ta.genericcodeid = icfgrp.genericcodeid"
and these are not working.
What is your suggestions?Your type will have to be created as an independent object in your schema. So CREATE TYPE cannot be in your function declaration, it has to be outside it. (And then the line inside your declaration that defines the type will have to be removed.)
But now I can see that you use this array as a kind of "temporary lookup table" - you populate the array and then use it for lookup in your select statement. An alternative way of doing this could be like this completely without arrays:
with othergenerics as (
select master.GENERICCODEID
from ASMTRG_ARTICLEMASTER master
join ASMTRG_ARTICLEMAP map on MAP.ARTICLECODEID = MASTER.ID
group by MASTER.GENERICCODEID
minus
select FGG.GENERICCODEID
from asmtrg_icfocusgroup fg
join asmtrg_icfocusgrpchannel fgc on FGC.GROUPID = FG.ID and fgc.isactive=1
join asmtrg_icfocusgengroup fgg on FGG.GROUPID = FG.ID and FGg.ISACTIVE=1
where fgc.channelid=1 and fg.isactive = 1
group by FGG.GENERICCODEID
SELECT icfrd.*,
CASE
WHEN EXISTS(select ta.genericcodeid from othergenerics ta where ta.genericcodeid = icfgrp.genericcodeid) THEN -1
ELSE icfrd.icfgroupid
END CLASSIFICATION
FROM ASMTRGVIW_ICFOCUSREPORTDATA icfrd
LEFT JOIN ASMTRG_ICFOCUSGROUP icfgrp on icfrd.ICFGROUPID = icfgrp.ID
WHERE (channelId IS NULL OR icfrd.CHANNELID = channelId)
AND (asmCodeId IS NULL OR icfrd.ASMCODEID = asmCodeId)
AND (yearId IS NULL OR icfrd.YEARID = yearId)
AND (monthId IS NULL OR icfrd.MONTHID = monthId)
...The with clause (subquery factoring) you can think of as a kind of temp table called othergenerics created "on-the-fly".
The optimizer may decide to actually create a temp table for you and use in the lookup, or it may decide to rewrite the query into suitable joins or nested loops or hashing - whatever the optimizer decides will be the optimal way of doing things :-)
So unless you use your array other places in your function, I would recommend dropping the array completely, skip populating an array, and instead use a with clause for your temporary lookup. -
Using Forumlas in (Command) SQL Query
We're trying to optimize the record returns on some reports and recently discovered the ability to apply a Command to specify the SQL Query.
One of the things we do with our reports is actually pass in some values so the user doesn't have to enter so many parameters. So we define a couple of formula tags and then pass values into those during the oninitialization portion of the crystal subclass in our program.
In our case these formula tags would be Jobcode and Division
Prior to our discovering the Command option, we were using those formulas in the Record and Group selections in this manner:
We would define two other formulas as thus:
sMyJobCode
ToText({@Jobcode})
sMyDivision
ToText({@Division})
and then we would call those in the Record and Group selection
example:
SELECT * from TableA where TableA.date between {?StartDate} and {?EndDate} and TableA.job = {@sMyJobCode} and TableA.division = {@sMyDivision}
My problem is that I can't figure out a way to include those formulas in the Command. It lets me use parameters (the date ranges in this case). But I need to get those two formula values (sMyJobCode and sMyDivision) pulled in as part of that initial SQL query because those values filter the record returns substantially.
Is there a way to do this? Any help on this would be greatly appreciated.An SQL Command can not use formula fields directly. I would think that using parameters - with default values set - would be just as easy for the user, and they could be used in the SQL.
Barring that, you could put the report into a subreport (if it is not already using subreports). Calculate the formula in the main report, and use the formula to link to the subreport's parameters, which are added as parameters to the subreport's SQL Command.
HTH,
Carl -
Error using Database addons with SQL query.
I get a LabVIEW error when I provide the following SQL query to the NI database VI: ..vi.lib\addons\database\Connection.llb\Conn Execute.vi.
declare @SR_ID table ( script_result_id uniqueidentifier )
insert into @SR_ID
select script_result_id from SCRIPT_RESULT
where script_result.software_name = '%s'
SELECT distinct STEP_RESULT.STEP_TYPE
FROM STEP_RESULT INNER JOIN @SR_ID s ON
STEP_RESULT.SCRIPT_RESULT_ID = s.script_result_id
The error is:
Error -2146824584 occurred at NI_Database_API.lvlib:Rec Destroy - Connection.vi->Database_Query Database with flattened string reply.vi->ADUTS-RPT Query DB.vi->ADUTS-RPT Get Step Names.vi->ADUTS-RPT Top.vi
Possible Reason(s): Exception occured in ADODB.Recordset: Operation is not allowed when the object is closed.
The query works fine when given directly to my SQL server.
Any ideas on this problem would be most appreciated.It looks like the bug is related to ADODB objects. I found a related KnowledgeBase article that was written about the same issue, but never published for some reason. Here's what it has to say about your error:
"This error occurs when a query is run on the database that does not return any recordset data, such as a delete command. In this case, when you encounter the DB Tools Fetch Recordset Data VI, the state of the recordset is "closed" and produces the error.
To avoid the error, you can check for the state of the recordset and make sure that it isn't closed. To do this, use the DB Tools Get Properties VI and check the state from the properties cluster. An additional, or alternate, check would be to check for the beginning of file and end of file properties. If both BOF and EOF are both true, there is no data in the recordset.
If you open the example program, Database Fetching, you can see that they are using both of these checks.
In versions of the toolset prior to version 1.0.2, these checks were built in. This causes code without the checks to return this error if the toolset is updated from a previous version."
Tim W.
Applications Engineering
National Instruments
http://www.ni.com/support -
Using view as a sql query in odisqlunload
Hi Expert,
I tried sql query in osisqlunload but that query retrieving the data from a view,even operator log shows successful execution data,but data is not getting into text file......
Is Odisqlunload supports views as sqlquery?
cheers,
surya
Edited by: surya on Apr 6, 2012 4:34 PMHi Bhabani,
Thanks for your prompt replay, it showing successfully executions, but data is not populating....
Do u have any links regarding this....
Cheers,
Surrya -
Changing A Value Using If Statement in SQL Query
Hello, I have a very rudimentary question that I'm stuck on. I have a query that returns one of 3 different integers. I want to have each integer translate to a string value depending on the number returned. Unfortunately this is the SCCM
database which cannot be changed to provide an additional table with the values.
I have something like this but I'm not getting what I want out of the date - depending on what I do I either get an error, or nothing.
Declare @NewValue nvarchar
Declare @Value nvarchar
If @Value = 1 Set @Value = 'String1'
If @Value = 2 Set @Value = 'String2'
If @Value = 3 Set @Value = 'String3'
Select PrimaryKey,IntegerValue FROM db_Table WHERE @Value=IntegerValue
I know this is a simple thing but I'm new to SQL and not exactly sure what terms I should even be using to search for this. Thanks for the help!select PrimaryKey, IntegerValue, case IntegerValue when 1 then 'String1'
when 2 then 'String 2' when 3 then 'String3' else 'Unknown Integer Value' end as [Description]
from db_Table
Take a look at
CASE expression in BOL. You may also find the following article helpful
http://social.technet.microsoft.com/wiki/contents/articles/21327.t-sql-simplified-case-expression.aspx
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
Not right data when row_number used in inner-view sql query...
Hi ,
I use the below sql statement which displays the right data
select CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE , SUM_POSOTITA , row_number() over(partition by code_farmakou order by sum_posotita desc) from
(SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES ,SUM(POSOTITA) SUM_POSOTITA
FROM EKTELESI_AT_SINT_CLINIC A, MITROO_FARMAKOU B
WHERE CODE_FARMAKOU = FARMAK_CODE
GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
UNION ALL
SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
FROM EKTELESI_AT_SINT_EX_IATR A, MITROO_FARMAKOU B
WHERE CODE_FARMAKOU = FARMAK_CODE
GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
UNION ALL
SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
FROM EKTELESI_AT_SINT_FOREON_MS A, MITROO_FARMAKOU B
WHERE CODE_FARMAKOU = FARMAK_CODE
GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
UNION ALL
SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
FROM EKTELESI_GEN_SINT_KLIN A, MITROO_FARMAKOU B
WHERE CODE_FARMAKOU = FARMAK_CODE
GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
UNION ALL
SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
FROM EKTELESI_GEN_SINT_EX_IATR A, MITROO_FARMAKOU B
WHERE CODE_FARMAKOU = FARMAK_CODE
GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS)The data are:
CODE_FARMAKOU EMP_NAME PACKTYPE PACKSIZE SUM_POSOTITA ROW_NUMBER()OVER(PARTITIONBYCO
0000002419 FACTREL INJECTION VIAL 2 ML 5 1
0000014071 DOPAMINE HYDROCHLORIDE VIAL 5 ML X 25 30 1
0000086289 DETUSSIN EXPECTORANT BOT 120 ML 3 1
1000000760 DEPON BT 20(BLIST2X10) 2 1
1000000760 DEPON BT 20(BLIST2X10) 1 2
1000003279 MOXACEF BT 40(BLIST10X4) 45 1
1000003279 MOXACEF BT 40(BLIST10X4) 1 2
1000003279 MOXACEF BT 40(BLIST10X4) 1 3
1000014127 DEPON VIT. C BT 2TUBX10 6 1
1000014127 DEPON VIT. C BT 2TUBX10 2 2
1000016655 KABIVEN BT 50ÖÕÓ.×1,7ML 21 1
1000016655 KABIVEN BT 50ÖÕÓ.×1,7ML 2 2However , when i use the below statement , in order not to display the row_number (so i use row_number function in inner-view) the data are different--in different order... why is that????
select CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE , SUM_POSOTITA from
select CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE , SUM_POSOTITA , row_number() over(partition by code_farmakou order by sum_posotita desc) from
(SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES ,SUM(POSOTITA) SUM_POSOTITA
FROM EKTELESI_AT_SINT_CLINIC A, MITROO_FARMAKOU B
WHERE CODE_FARMAKOU = FARMAK_CODE
GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
UNION ALL
SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
FROM EKTELESI_AT_SINT_EX_IATR A, MITROO_FARMAKOU B
WHERE CODE_FARMAKOU = FARMAK_CODE
GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
UNION ALL
SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
FROM EKTELESI_AT_SINT_FOREON_MS A, MITROO_FARMAKOU B
WHERE CODE_FARMAKOU = FARMAK_CODE
GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
UNION ALL
SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
FROM EKTELESI_GEN_SINT_KLIN A, MITROO_FARMAKOU B
WHERE CODE_FARMAKOU = FARMAK_CODE
GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
UNION ALL
SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
FROM EKTELESI_GEN_SINT_EX_IATR A, MITROO_FARMAKOU B
WHERE CODE_FARMAKOU = FARMAK_CODE
GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS)
)and its data are:
CODE_FARMAKOU EMP_NAME PACKTYPE PACKSIZE SUM_POSOTITA
1000016655 KABIVEN BT 50ΦΥΣ.Χ1,7ML 21
1000016655 KABIVEN BT 50ΦΥΣ.Χ1,7ML 2
1000000760 DEPON BT 20(BLIST2X10) 2
1000014127 DEPON VIT. C BT 2TUBX10 2
1000003279 MOXACEF BT 40(BLIST10X4) 45
0000014071 DOPAMINE HYDROCHLORIDE VIAL 5 ML X 25 30
0000086289 DETUSSIN EXPECTORANT BOT 120 ML 3
1000014127 DEPON VIT. C BT 2TUBX10 6
1000003279 MOXACEF BT 40(BLIST10X4) 1
1000003279 MOXACEF BT 40(BLIST10X4) 1
0000002419 FACTREL INJECTION VIAL 2 ML 5
1000000760 DEPON BT 20(BLIST2X10) 1NOTE :Sorry, I tried to pose some sample data using the "with" statement but i couldn't...the error ORA-32035 : unreferenced query name defined in WITH clause was displayed..
Regards,
SimonThe optimizer has, well, optimized out the row_number because you never refer to its value in the outermost query.
sql>select deptno, cnt, row_number() over (order by cnt desc) rn
2 from (select deptno, count(*) cnt
3 from emp
4 group by deptno);
DEPTNO CNT RN
30 6 1
20 5 2
10 3 3
3 rows selected.
-- here because we include rn in the outermost query,
-- the results are still ordered based on the analytical function result
sql>select deptno, cnt, rn
2 from (select deptno, cnt, row_number() over (order by cnt desc) rn
3 from (select deptno, count(*) cnt
4 from emp
5 group by deptno));
DEPTNO CNT RN
30 6 1
20 5 2
10 3 3
3 rows selected.
-- but if we don't include rn in the outermost query,
-- the optimizer leaves out the window sort and the results are in a different order
sql>select deptno, cnt
2 from (select deptno, cnt, row_number() over (order by cnt desc) rn
3 from (select deptno, count(*) cnt
4 from emp
5 group by deptno));
DEPTNO CNT
10 3
20 5
30 6
3 rows selected.This just reinforces the point that if you want your results in a particular order, you need to provide an ORDER BY clause - don't rely on execution plans to do your sorting for you. -
How to use check box in SQL Query
Hi
I have a reagion with check boxes. Now I am creating another region which is
PL/SQL function/block returning query.
here' the block. When I save it give me error
Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the ''generic columns'' checkbox below the region source to proceed without parsing. ORA-00900: invalid SQL statement
Here is the code
DECLARE
p_str VARCHAR2(2000);
p_col_name varchar2(100);
p_flg char(1);
BEGIN
p_flg := 'N';
for i in 1 .. htmldb_application.g_f01.count
LOOP
p_flg := 'Y';
p_col_name := htmldb_application.g_f01(i);
IF i = 1
THEN
p_str := 'SELECT ' || p_col_name;
ELSE
p_str := p_str || ', ' || p_col_name;
END IF;
END LOOP;
p_str := p_str || ' FROM UALDBA_V';
RETURN p_str;
END;
Please advice
SunilSunil - The htmldb_application.g_fxx arrays are empty during page rendering. A query cannot be generated using them.
Scott -
Using "LIKE" in J2EE SQL Query Window
Whats the syntax to define a finder method using the SQL "LIKE" clause in J2EE in the deployment settings of an CMP entity bean...for example lets say I have an entity bean with a primary ket called "PK" and a String data member called "Titile", I've tried:
SELECT "PK" FROM "EntityBeanTable" WHERE "Title" LIKE
%?1%
but that doesn't work...any suggestions?I believe the solution may be vendor specific. i am using weblogic5.1 and i use CMP entity beans.
Now the if i want a sql with like clause, then i give in the following entries in my
weblogic-cmp-rdbms-jar.xml
<finder>
<method-name>findByPrimaryKey</method-name>
<method-params>
<method-param>java.lang.Long</method-param>
</method-params>
<finder-query><![CDATA[ (like acctCode $0)]]></finder-query>
</finder>
for more options please refer u r vendor documentations.
regards
rajesh -
Replace Values for a Col under a Table using Replace Function in Sql Query
Hi all
I have a Custom Table by Name RESP_TABLE which stores the Responsibility Names under the Column RESPONSIBILITY.
The Sample Value for this col is as follows :
PF <CNTRY> Gl Analyst <CCY>.
This <CNTRY> Stands for Country Short Name
and <CCY> Stands for Currency.
The <CNTRY> & <CCY> should be passed as a parameter at the run time.
Based on the value given at the run time it should change accordingly.
For example
PF <CNTRY> Gl Analyst <CCY>
<CNTRY> Value passed at runtime : BE
<CCY> Value passed at runtime : CAD
So the resulting value should be as follows :
PF BE Gl Analyst CAD.
I had already used the query given below :
SELECT REPLACE(RESPONSIBILITY,'<CNTRY>','&MARKET') FROM RESP_TABLE.
This works fine for Country Code alone but not for currency.
I need both the Country Code and Currency Code to be changed to the respective values given at the runtime.
Could anybody please help me on this ?
Regards
Nakul Venkataraman.Hi Nakul,
Why not just adding another REPLACE to what you still have achieved? :)
Regards,
Guido
Maybe you are looking for
-
If you create a Pdf using Indesign, import into Acrobat Pro and add text etc.....if you then save the Pdf to email to customers, the text entered using Acrobat Pro does not show in mobile devices!
-
Signer messaging not working in Safari
I have customised my signer messaging for my widget which is appearing in Chrome and in Safari Mobile but not in Safari Desktop on Mac. I don't think it is a cache issue as I am clearing cache and other test changes I make are appearing. It is not sh
-
Pacleanup: A script to clean up package bloat
Hi all! Here is my first real contribution to the Arch community! w00t! Do you install packages just to try them out and never end up using them? Do you forget about them and do they just add to the bloat on your system? Do you want to review the pac
-
Does ipad have bluetooth to be able to connect iphone internet to the ipad?
does ipad have bluetooth that will allow the iphone's internet to be used by the ipad?
-
How to Activate T.code LBK1
Hi guru's, While opening SAP Std T.code LBK1 , systerm is giving error ' transaction doesnot exists ', I know there are some badis we need to implement, but need some help regarding implementation. I want to activate this transaction..for log book en