SQL query - Alias name (value) as parameter to an Oracle function
Hi,
I have a sql query something like
Select tbl1.valueA, tbl1.valueB, tbl2.valueX, MAX(CASE tbl2.valueY = 'XX' THEN tbl2.valueZ END) AS "ValueZ header", Function(tbl1.valueB, tbl2.valueX, "valueZ header")
FROM table1 tbl1
JOIN table2 tbl2 ON tbl1.id = tbl2.tbl1id
WHERE ...
my problem is that I need the value from MAX statement as parameter to the function and I have tried to use the alias name (valueZ header) but this is not working. I guess because of some syntax error. Can I use alias name as parameter into the function at all - if - how should I do this?
Hi,
user8819407 wrote:
Hi,
I have a sql query something like
Select tbl1.valueA, tbl1.valueB, tbl2.valueX, MAX(CASE tbl2.valueY = 'XX' THEN tbl2.valueZ END) AS "ValueZ header", Function(tbl1.valueB, tbl2.valueX, "valueZ header")
FROM table1 tbl1
JOIN table2 tbl2 ON tbl1.id = tbl2.tbl1id
WHERE ...
my problem is that I need the value from MAX statement as parameter to the function and I have tried to use the alias name (valueZ header) but this is not working. I guess because of some syntax error. Can I use alias name as parameter into the function at all - if - how should I do this?You can use a column alias in the ORDER BY clause of the same query where it was defined, but that's the only place where you can use it in that query.
You could repeat the entire MAX (CASE ...) expression as the 3rd argumnet to your function, or you could compute it once in a sub-query, then reference the column alias as often as you like in the super-query, like this:
WITH got_valuez_header AS
Select tbl1.valueA
, tbl1.valueB
, tbl2.valueX
, MAX ( CASE
WEHN tbl2.valueY = 'XX' -- Don't forget the keyword WHEN
THEN tbl2.valueZ
END
) AS "ValueZ header"
FROM table1 tbl1
JOIN table2 tbl2 ON tbl1.id = tbl2.tbl1id
WHERE ...
GROUP BY ...
Select tbl1.valueA
, tbl1.valueB
, tbl2.valueX
, "ValueZ header"
, Function_x ( tbl1.valueB -- FUNCTION is not a good name for a function
, tbl2.valueX
, "ValueZ header" -- Case-sensitive
FROM got_valuez_header
;
Similar Messages
-
SQL query alias names errors with dynamic lists
Hullo,
Problem:
- Made a query form book database. Have authors in separate table with unique ID's referring to them on book table.
- Query fetches author name in "Surname, Firstname initial.Secondfirstname initial" format, --> like "Bukowski, H.C" and giving that combo alias name in SQL like "AS 'author'"...
- Dynamic list works fine at start, but when ordered from detail table back to the mainlisting, it does make an error with SQL stating "unknown column 'author' in where clause"
That must be because the script looks for "author" column from the original table yeah, but how can I solve this? Any ideas? Does this mean that Alias names for columns are not possible or is there something i've missed?
Any ideas, suggestions?
Thanks,
KimmoKHi Kimmo,
ADDT´s dynamic lists can handle alias columns fine to my experience, but I reckon that you most probably applied the "CONCAT(...) AS author" query modification after having generated the list, and the list´s internal WHERE clause seems to have no clue of this alias column.
You can get an idea about using alias columns in Dynamic Lists in my tutorial "Dynamic Lists: exploring the Filter Conditions": http://www.guenter-schenk.com/tutorials/tutorial.php?id=6
Can you please post the list´s code on your server as text file (e.g. code.txt) and provide a link to this file ?
Cheers,
Günter Schenk
Adobe Community Expert, Dreamweaver -
How could I replace hard coded value in my sql query with constant value?
Hi all,
Could anyone help me how to replace hardcoded value in my sql query with constant value that might be pre defined .
PROCEDURE class_by_day_get_bin_data
in_report_parameter_id IN NUMBER,
in_site_id IN NUMBER,
in_start_date_time IN TIMESTAMP,
in_end_date_time IN TIMESTAMP,
in_report_level_min IN NUMBER,
in_report_level_max IN NUMBER
IS
bin_period_length NUMBER(6,0);
BEGIN
SELECT MAX(period_length)
INTO bin_period_length
FROM bin_data
JOIN site_to_data_source_lane_v
ON bin_data.data_source_id = site_to_data_source_lane_v.data_source_id
JOIN bin_types
ON bin_types.bin_type = bin_data.bin_type
WHERE site_to_data_source_lane_v.site_id = in_site_id
AND bin_data.start_date_time >= in_start_date_time - numtodsinterval(1, 'DAY')
AND bin_data.start_date_time < in_end_date_time + numtodsinterval(1, 'DAY')
AND bin_data.bin_type = 2
AND bin_data.period_length <= 60;
--Clear the edr_class_by_day_bin_data temporary table and populate it with the data for the requested
--report.
DELETE FROM edr_class_by_day_bin_data;
SELECT site_to_data_source_lane_v.site_id,
site_to_data_source_lane_v.site_lane_id,
site_to_data_source_lane_v.site_direction_id,
site_to_data_source_lane_v.site_direction_name,
bin_data_set.start_date_time,
bin_data_set.end_date_time,
bin_data_value.bin_id,
bin_data_value.bin_value
FROM bin_data
JOIN bin_data_set
ON bin_data.bin_serial = bin_data_set.bin_serial
JOIN bin_data_value
ON bin_data_set.bin_data_set_serial = bin_data_value.bin_data_set_serial
JOIN site_to_data_source_lane_v
ON bin_data.data_source_id = site_to_data_source_lane_v.data_source_id
AND bin_data_set.lane = site_to_data_source_lane_v.data_source_lane_id
JOIN (
SELECT CAST(report_parameter_value AS NUMBER) lane_id
FROM report_parameters
WHERE report_parameters.report_parameter_id = in_report_parameter_id
AND report_parameters.report_parameter_group = 'LANE'
AND report_parameters.report_parameter_name = 'LANE'
) report_lanes
ON site_to_data_source_lane_v.site_lane_id = report_lanes.lane_id
JOIN (
SELECT CAST(report_parameter_value AS NUMBER) class_id
FROM report_parameters
WHERE report_parameters.report_parameter_id = in_report_parameter_id
AND report_parameters.report_parameter_group = 'CLASS'
AND report_parameters.report_parameter_name = 'CLASS'
) report_classes
ON bin_data_value.bin_id = report_classes.class_id
JOIN edr_rpt_tmp_inclusion_table
ON TRUNC(bin_data_set.start_date_time) = TRUNC(edr_rpt_tmp_inclusion_table.date_time)
WHERE site_to_data_source_lane_v.site_id = in_site_id
AND bin_data.start_date_time >= in_start_date_time - numtodsinterval(1, 'DAY')
AND bin_data.start_date_time < in_end_date_time + numtodsinterval(1, 'DAY')
AND bin_data_set.start_date_time >= in_start_date_time
AND bin_data_set.start_date_time < in_end_date_time
AND bin_data.bin_type = 2
AND bin_data.period_length = bin_period_length;
END class_by_day_get_bin_data;In the above code I'm using the hard coded value 2 for bin type
bin_data.bin_type = 2But I dont want any hard coded number or string in the query.
How could I replace it?
I defined conatant value like below inside my package body where the actual procedure comes.But I'm not sure whether I have to declare it inside package body or inside the procedure.
bin_type CONSTANT NUMBER := 2;But it does't look for this value. So I'm not able to get desired value for the report .
Thanks.
Edited by: user10641405 on May 29, 2009 1:38 PMDeclare the constant inside the procedure.
PROCEDURE class_by_day_get_bin_data(in_report_parameter_id IN NUMBER,
in_site_id IN NUMBER,
in_start_date_time IN TIMESTAMP,
in_end_date_time IN TIMESTAMP,
in_report_level_min IN NUMBER,
in_report_level_max IN NUMBER) IS
bin_period_length NUMBER(6, 0);
v_bin_type CONSTANT NUMBER := 2;
BEGIN
SELECT MAX(period_length)
INTO bin_period_length
FROM bin_data
JOIN site_to_data_source_lane_v ON bin_data.data_source_id =
site_to_data_source_lane_v.data_source_id
JOIN bin_types ON bin_types.bin_type = bin_data.bin_type
WHERE site_to_data_source_lane_v.site_id = in_site_id
AND bin_data.start_date_time >=
in_start_date_time - numtodsinterval(1, 'DAY')
AND bin_data.start_date_time <
in_end_date_time + numtodsinterval(1, 'DAY')
AND bin_data.bin_type = v_bin_type
AND bin_data.period_length <= 60;
--Clear the edr_class_by_day_bin_data temporary table and populate it with the data for the requested
--report.
DELETE FROM edr_class_by_day_bin_data;
INSERT INTO edr_class_by_day_bin_data
(site_id,
site_lane_id,
site_direction_id,
site_direction_name,
bin_start_date_time,
bin_end_date_time,
bin_id,
bin_value)
SELECT site_to_data_source_lane_v.site_id,
site_to_data_source_lane_v.site_lane_id,
site_to_data_source_lane_v.site_direction_id,
site_to_data_source_lane_v.site_direction_name,
bin_data_set.start_date_time,
bin_data_set.end_date_time,
bin_data_value.bin_id,
bin_data_value.bin_value
FROM bin_data
JOIN bin_data_set ON bin_data.bin_serial = bin_data_set.bin_serial
JOIN bin_data_value ON bin_data_set.bin_data_set_serial =
bin_data_value.bin_data_set_serial
JOIN site_to_data_source_lane_v ON bin_data.data_source_id =
site_to_data_source_lane_v.data_source_id
AND bin_data_set.lane =
site_to_data_source_lane_v.data_source_lane_id
JOIN (SELECT CAST(report_parameter_value AS NUMBER) lane_id
FROM report_parameters
WHERE report_parameters.report_parameter_id =
in_report_parameter_id
AND report_parameters.report_parameter_group = 'LANE'
AND report_parameters.report_parameter_name = 'LANE') report_lanes ON site_to_data_source_lane_v.site_lane_id =
report_lanes.lane_id
JOIN (SELECT CAST(report_parameter_value AS NUMBER) class_id
FROM report_parameters
WHERE report_parameters.report_parameter_id =
in_report_parameter_id
AND report_parameters.report_parameter_group = 'CLASS'
AND report_parameters.report_parameter_name = 'CLASS') report_classes ON bin_data_value.bin_id =
report_classes.class_id
JOIN edr_rpt_tmp_inclusion_table ON TRUNC(bin_data_set.start_date_time) =
TRUNC(edr_rpt_tmp_inclusion_table.date_time)
WHERE site_to_data_source_lane_v.site_id = in_site_id
AND bin_data.start_date_time >=
in_start_date_time - numtodsinterval(1, 'DAY')
AND bin_data.start_date_time <
in_end_date_time + numtodsinterval(1, 'DAY')
AND bin_data_set.start_date_time >= in_start_date_time
AND bin_data_set.start_date_time < in_end_date_time
AND bin_data.bin_type = v_bin_type
AND bin_data.period_length = bin_period_length;
END class_by_day_get_bin_data; -
Sql Loader INFILE name value in table column Value
Hi,
Here is my Sql Loader Script
LOAD DATA
infile '%1'
APPEND INTO TABLE XX_SUPPLIER_UPD
FIELDS TERMINATED BY ";" OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
ACTION Char
,ADDRESS_TYPE Char
,REGION Char "LTRIM(RTRIM(:REGION))"
,PO_BOX Char
,,WWW_ADDRESS Char
,status Char "NVL(:status,'X')"
,filename Char "replace(:infile,'\"','')"
I am getting the infile name as the parameter and i want to insert that parameter value in the column name fillename. Can any one guide me to how to do.
Cheers!
Jayaraj.SIf you were to use external tables instead of SQL*Loader, you can dynamically change the location of the external table (i.e. the filename) using a simple ALTER TABLE statement.
External tables also mean that all the control is inside the database rather than relying on external utilities and external scripts.
;) -
Inserting field text into sql query and comparing values to another table
I have an issue in Visual Web Developer 2010 that I need help with.
The code below is a Gridview Sql query where I'm extracting PART_NUMBER from various tables. I would like to add the table name in a separate field named Table. The end result should appear as follows:
PART_NUMBER Table
010-0075-06 Resistors (or Capacitors, etc.)
Sql query:
SELECT PART_NUMBER
FROM Capacitors
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Connectors
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Diodes
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM ICs
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Inductors
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Misc
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Relays
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Resistors
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Switches
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Transformers
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Transistors
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM [Crystals and Oscillators]
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
ORDER BY PART_NUMBER
I have a separate table (CIS Manufacturer Parts) that contains manufacturer data for the above parts. Multiple manufacturer rows can exist. The connection between tables in the PART_NUMBER field. What I would like to do is make this query
add the table name to the gridview output listing only parts without manufacturer data and the table they can be found in.
This is a lot for a newbie so I will appreciate any help, thanks!Hello Bulldog248,
Thank you for your post.
Your issue is out of support range of VS General Question forum which mainly discusses the usage issue of Visual Studio IDE such as
WPF & SL designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System
and Visual Studio Editor.
I am moving your question to the moderator forum ("Where is the forum for..?"). The owner of the forum will direct you to a right forum.
Best regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
JDBC Url for connecting SQL Server Alias name
Hi All,
I am having a SqlServer Databse Instance for that we have created "alias name".
i am unable to connect to that particular alias name.
please can any one though light on this plz.
Edited by: mahesh512 on Jun 17, 2009 6:48 PMIf i am geussing right, you mean that you have created a TNS Name for your Database Server.
If you are accessing it from your DB Client via the TNS name, maybe the CLient is configured to contact a TNS Server to retrieve the IP if the server.
Your JDBC Driver does not do that. Either use the IP of the DB Server or provide a Source for the Driver to look up the IP via the TNS Name.
How this is accomplished deplends on your Database. -
SQL query result shoes value ids instead of value names
Hi All,
Pleaes i need help.
When selecting top 1000 result from a table, it give me a lot of result taht are useful for me. But one column named "subcategory", it give me the Subcategory ID instead of Subcategory NAme
The Subcategory Information are taken from another column that belong to another table (sometimes from another DB)
I would like to substitue (or somethink similar) the subcategory ID's with Subcagtegory names.
here details:
Date
Category Name (CATEGORY)
Subcategory ID (ITEM ID)
Date
Name of Table 1 belonging to Another DB 1 in Altro DB
Item ID, that is present in a Column of Table 1
Date
Name of Table 4 belonging to Another DB 1 in Altro DB
Item ID, that is present in a Column of Table 4
Date
Name of Table 1 Belonging to Another DB 1 in Altro DB
Item ID, that is present in a Column of Table 1
Date
Name of Table 2 Belonging to Another DB 1 in Altro DB
Item ID, that is present in a Column of Table 2
Can you help me please?
thanksI think what you need is a simple join
ie like below
SELECT t.[Date],t.CATEGORY,s.SUBCATEGORYNAME,.. other columns
FROM YourTable t
INNER JOIN AltroDB.dbo.SUbCategoryTable s
ON s.IDField = t.ITEMID
IDField is field corresponding to ITEMID value in subcategory table.
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
SBO SQL Query outputs zero values as nulls but need the zeros
Hi all,
I'm having a problem with a query I'm writing in SBO where if the field contents are zero, these are output as null.
I have a field for the stock usage on sales orders and ont too for production orders, but if I add these together they only provide a result if both columns contain a numeric value.
I've tried adding "0" to the column value, adding and subtracting "1" and also multiplying the value by "1" but still no joy.
I have also tried adding a "cast" statement to the column, but that doesnt seem to have an effect either (I think as this is more an output function).
I need to be able to use these columns as separate displays in addition to being used in a further column as part of a calculation.
If anyone has an idea how I can output a true zero value as opposed to a null value your help would be appreciated.
Cheers,
JHello Julian,
You could try to use a CASE Statement as I have shown below and test this will the SQL below. If you use the T0.LineNum without any CASE or CAST the LineNum 0 will show as blank in SAP.
SELECT
CASE WHEN T0.LineNum != 0 THEN CAST(T0.LineNum AS VARCHAR(10)) ELSE '0' END AS 'Row Number',
T0.ItemCode AS 'Item No.', T0.BaseQty AS 'Base Quantity', T0.PlannedQty AS 'Planned Quantity - Rows' FROM [dbo\].[WOR1\] T0 -
SQL query for updating values in same cell of a table
Hi All,
I'm stuck with a problem and it stands as follows:
Table name: Track
Part1 Part2 Part3
NULL NULL NULL
I've a table called Track, which has three columns named Part1, Part2 and Part3. I want all values of Part1 to be separated by a comma (,); it should not be overwritten, neither they should appear in separate row, in fact they should look like this:
Part1 Part2 Part3
1,2,3 5 SUBM1
The new values of Part1 should appear in next row only when value of Part3 changes, so if Part3 changes from SUBM1 to SUBM2, it should look like this:
Part1 Part2 Part3
1,2,3 5 SUBM1
1,2,3 5 SUBM2
Count of values in Part1 never exceeds the value of Part2, so if Part2 is 5, then Part1 will look like 1,2,3,4,5. So in other words loop will run only up to the value of Part2.
Please advise how this could be achieved?
Kind regards,
Aniruddha JagdaleI've a table called Track, which has three columns named Part1, Part2 and Part3. I want all values of Part1 to be separated by a comma (,);
No, don't go there.
This breaks a fundamental point for relational databases: no repeating groups. A cell should hold an atomic value. And this is not only a matter of purism. Relational databases are designed from this principle, and breaking this means that you will need
to write complex and higly inefficient code.
The values in Part1 should be in a separate table, with one value per row.
Erland Sommarskog, SQL Server MVP, [email protected] -
SQL Query for max values!!
Hi to all,
I have four tables
Tbl_one
Tbl_two
Tbl_three
Tbl_four
the relation between these tables is
Tbl_one.SEQ = Tbl_two.SEQ)
and tbl_two.case_SEQ = Tbl_four.SEQ
AND Tbl_two.ORDER_SEQ = tbl_three.SEQ))
I want a query like this
Select tbl_one.com_name, tbl_three.test_date,tbl_four.order_date
from Tbl_one,Tbl_two,Tbl_three,Tbl_four
where Tbl_one.SEQ = Tbl_two.SEQ)
and tbl_two.case_SEQ = Tbl_four.SEQ
AND Tbl_two.ORDER_SEQ = tbl_three.SEQ))
and tbl_three.test_date in (select max(test_date) from tbl_three)
and tbl_four.order_date in select(max(order_date from tbl_for)
and max(test_date)> Max(order_date)
any way it is possible?
the real problem is there are multiple test_dates and
multiple order_date for same seq in tbl_one.seq.
eg: -
name (indian) which has three or more test_date and each test_date have more than one order_date
indian (name) 01/01/2009(test_date) has ---- 01/10/2009, 01/20/2009 and 01/21/2009) order_dates
india(name) 02/02/2009 (test_date) has ----- 02/10/2009, 02/20/2009 and 02/30/2009 (order_dates)
india(name) 03/03/2009 test_date has ----- 03/10/2009, 03/20/2009 , 03/25/2009 (order_dates).
japan has the same situation and so on
what i wanted from the query is
max(test_date)= 03/03/2009 > max(order_date)=03/25/2009
ans: -
name
india(name) 03/03/2009 (test_date) 03/25/2009(order_date)
etc. etc . etc.
thanks!!
Edited by: pl/sql baby on Mar 24, 2009 10:45 AM
Edited by: pl/sql baby on Mar 24, 2009 10:47 AM
Edited by: pl/sql baby on Mar 24, 2009 10:51 AM
Edited by: pl/sql baby on Mar 24, 2009 10:57 AMPlease use tags either side of code / data (to preserve the formatting and spacing).
I don't understand your requirement... 03/03/2009 is not greater than 03/25/2009 ?
Could you please be clearer in your input/output samples and explain more about how to generate the output? -
How to find sql query using hash value
Hi,
DBVERSION: 9.2.0.8
I generated statspack report and i want to see total query and i have hash_value here.
in v$sql am not able to see all the querys ...pls suggest me other ways..
Thanks,
Srini...Srini wrote:
Thanks Nikolay,
But that views are not available in 9i , my DB is in 9.2.0.8...Use v$SQLAREA
SQL> desc v$sqlarea
Name Null? Type
SQL_TEXT VARCHAR2(1000)
SQL_FULLTEXT CLOB
SQL_ID VARCHAR2(13)
SHARABLE_MEM NUMBER
PERSISTENT_MEM NUMBER
RUNTIME_MEM NUMBER
SORTS NUMBER
VERSION_COUNT NUMBER
LOADED_VERSIONS NUMBER
OPEN_VERSIONS NUMBER
USERS_OPENING NUMBER
FETCHES NUMBER
EXECUTIONS NUMBER
PX_SERVERS_EXECUTIONS NUMBER
END_OF_FETCH_COUNT NUMBER
USERS_EXECUTING NUMBER
LOADS NUMBER
FIRST_LOAD_TIME VARCHAR2(19)
INVALIDATIONS NUMBER
PARSE_CALLS NUMBER
DISK_READS NUMBER
DIRECT_WRITES NUMBER
BUFFER_GETS NUMBER
APPLICATION_WAIT_TIME NUMBER
CONCURRENCY_WAIT_TIME NUMBER
CLUSTER_WAIT_TIME NUMBER
USER_IO_WAIT_TIME NUMBER
PLSQL_EXEC_TIME NUMBER
JAVA_EXEC_TIME NUMBER
ROWS_PROCESSED NUMBER
COMMAND_TYPE NUMBER
OPTIMIZER_MODE VARCHAR2(10)
OPTIMIZER_COST NUMBER
OPTIMIZER_ENV RAW(2000)
OPTIMIZER_ENV_HASH_VALUE NUMBER
PARSING_USER_ID NUMBER
PARSING_SCHEMA_ID NUMBER
PARSING_SCHEMA_NAME VARCHAR2(30)
KEPT_VERSIONS NUMBER
ADDRESS RAW(4)
HASH_VALUE NUMBER
OLD_HASH_VALUE NUMBER
PLAN_HASH_VALUE NUMBER
MODULE VARCHAR2(64)
MODULE_HASH NUMBER
ACTION VARCHAR2(64)
ACTION_HASH NUMBER
SERIALIZABLE_ABORTS NUMBER
OUTLINE_CATEGORY VARCHAR2(64)
CPU_TIME NUMBER
ELAPSED_TIME NUMBER
OUTLINE_SID VARCHAR2(40)
LAST_ACTIVE_CHILD_ADDRESS RAW(4)
REMOTE VARCHAR2(1)
OBJECT_STATUS VARCHAR2(19)
LITERAL_HASH_VALUE NUMBER
LAST_LOAD_TIME DATE
IS_OBSOLETE VARCHAR2(1)
IS_BIND_SENSITIVE VARCHAR2(1)
IS_BIND_AWARE VARCHAR2(1)
CHILD_LATCH NUMBER
SQL_PROFILE VARCHAR2(64)
SQL_PATCH VARCHAR2(30)
SQL_PLAN_BASELINE VARCHAR2(30)
PROGRAM_ID NUMBER
PROGRAM_LINE# NUMBER
EXACT_MATCHING_SIGNATURE NUMBER
FORCE_MATCHING_SIGNATURE NUMBER
LAST_ACTIVE_TIME DATE
BIND_DATA RAW(2000)
TYPECHECK_MEM NUMBER
IO_CELL_OFFLOAD_ELIGIBLE_BYTES NUMBER
IO_INTERCONNECT_BYTES NUMBER
PHYSICAL_READ_REQUESTS NUMBER
PHYSICAL_READ_BYTES NUMBER
PHYSICAL_WRITE_REQUESTS NUMBER
PHYSICAL_WRITE_BYTES NUMBER
OPTIMIZED_PHY_READ_REQUESTS NUMBER
LOCKED_TOTAL NUMBER
PINNED_TOTAL NUMBER
IO_CELL_UNCOMPRESSED_BYTES NUMBER
IO_CELL_OFFLOAD_RETURNED_BYTES NUMBERYou have HASH_VALUE and SQL_FULLTEXT to identify your query. Remember if query is long then you needt to set proper parameters like
set long 80000
set pagesize 200
set linessize 200
Was that helpful? -
How to execute PL/SQL query based on given input parameter
Hi all,
I have a pl/sql code which is in Region source. It extracts data from database. I want to execute the code based on input I give. I have to give date as a input parameter.
e.g.
If I give date1 as a parameter, then following code should executed
select col1, col2,..... from Table where date1 between '01-jan-2010' and '31-jan-2010'
If I give date2 as a parameter, then following code should executed
select col1, col2,..... from Table where date2 between '01-jan-2010' and '31-jan-2010'
Your help is very much appreciated.
LeoCheck the datatemplate,lexicals and beforeTrigger for this in documentation.
check this
Lexical reference issue in EBS -
SQL Query for take values on excle sheet
i have the query `select EmpId,AttenDate,status from dbo.Attendance`
it will give me this
1500011 2014-09-01 00:00:00.000
A
1500011 2014-09-02 00:00:00.000
A
1500011 2014-09-03 00:00:00.000
A
1500011 2014-09-04 00:00:00.000
A
1500011 2014-09-05 00:00:00.000
A
1500011 2014-09-06 00:00:00.000
P
1500011 2014-09-07 00:00:00.000
A
upto 2014-09-31 00:00:00.000
A
68 2014-08-01 00:00:00.000
A
68 2014-08-02 00:00:00.000
P
68 2014-08-03 00:00:00.000
A
68 2014-09-07 00:00:00.000 A
upto 2014-09-31 00:00:00.000
A
Now i want to print it into the excel sheet
with is format
Empid 1
2 3
4 5
6 7
8 upto 31
1500011 A A A
A A
P A
A upto A
68 A
A P
....................upto A
Please suggest me??
Hi SachinDholess,
Based on my understanding, you want to merge the attendance records for each EmpID into one row as below snapshot rather than in rows, right?
According to your description, I created and populate the attendance records of September for EmpID
1500011 and records of August and September for EmpID 68
to simulate your scenario. In this scenario, the Stored Procedure
procGetEmpAtt would help you to get the data like above snapshot during a given period. Please see the below code.
USE TestDB;
IF OBJECT_ID('dbo.Attendance') IS NOT NULL
DROP TABLE dbo.Attendance;
GO
CREATE TABLE Attendance
EmpID INT,
AttenDate DATETIME,
[status] VARCHAR(99)
GO
--Create and Populate the Nums Auxiliary Table
SET NOCOUNT ON;
SET ROWCOUNT 0;
IF OBJECT_ID('dbo.Nums', 'U') IS NOT NULL
DROP TABLE dbo.Nums;
CREATE TABLE dbo.Nums(n INT NOT NULL PRIMARY KEY);
DECLARE @max AS INT, @rc AS INT;
SET @max = 1000;
SET @rc = 1;
INSERT INTO dbo.Nums(n) VALUES(1);
WHILE @rc * 2 <= @max
BEGIN
INSERT INTO dbo.Nums(n) SELECT n + @rc FROM dbo.Nums;
SET @rc = @rc * 2;
END
INSERT INTO dbo.Nums(n)
SELECT n + @rc FROM dbo.Nums WHERE n + @rc <= @max;
GO
--Insert records of September for EmpID 1500011
INSERT INTO Attendance VALUES(1500011,'2014-09-01 00:00:00.000', 'A');
INSERT INTO Attendance
SELECT EmpID, DATEADD(DAY,n,AttenDate), [status] FROM Attendance join nums ON nums.n<30
WHERE EMPID=1500011;
--Insert records of September and August for EmpID 68
INSERT INTO Attendance VALUES(68,'2014-08-01 00:00:00.000', 'A');
INSERT INTO Attendance
SELECT EmpID, DATEADD(DAY,n,AttenDate), [status] FROM Attendance join nums ON nums.n<61
WHERE EMPID=68;
DROP TABLE dbo.Nums;
IF (OBJECT_ID('procGetEmpAtt', 'P') IS NOT NULL)
DROP PROC procGetEmpAtt
GO
CREATE PROC procGetEmpAtt(@startDT DATETIME, @endDT DATETIME)
AS
DECLARE @DynamicPivotQuery AS NVARCHAR(MAX);
DECLARE @ColumnName AS NVARCHAR(MAX);
DECLARE @Columns AS NVARCHAR(MAX);
--Get distinct values of the PIVOT Column
SELECT @ColumnName= ISNULL(@ColumnName + ',','')+ 'ISNULL('+QUOTENAME(dt)+',''Not Recored'') AS '+QUOTENAME(dt),
@Columns=ISNULL(@Columns + ',','')+QUOTENAME(dt)
FROM (SELECT DISTINCT CONVERT(varchar(12) , AttenDate, 112 ) as dt FROM Attendance WHERE AttenDate BETWEEN @startDT AND @endDT ) AS A ;
--Prepare the dynamic PIVOT query
SET @DynamicPivotQuery =
N'SELECT EmpID, ' + @ColumnName + '
FROM Attendance
PIVOT(MAX([status])
FOR AttenDate IN (' + @Columns + ')) AS PVTTable ORDER BY EmpID DESC' ;
--Execute the dynamic Pivot Query
EXEC sp_executesql @DynamicPivotQuery ;
GO
Test example
SET NOCOUNT ON;
SET ROWCOUNT 0;
EXEC procGetEmpAtt
@startDT='2014-08-29',
@endDT='2014-09-15'
The key in this Stored Procedure is the dynamic Pivot statement, click
here for more details.
By the way, I didn’t quite get your point until I copied your description into a Word document. Kindly mind the format of the description you post, a better formatted one would lead to a much quicker response.
If you have any question, feel free to let me know.
Best Regards,
Eric Zhang -
Hi,
I am having following data in Oracle 9i
create table toto ( a number, flag varchar2(1));
insert into toto values (1, 'U');
insert into toto values (1, 'O');
insert into toto values (2, 'U');
insert into toto values (3, 'U');
insert into toto values (3, 'O');
insert into toto values (4, 'U');
insert into toto values (4, 'O');
insert into toto values (4, 'I');
insert into toto values (4, 'L');
insert into toto values (5, 'U');
insert into toto values (6, 'O');
insert into toto values (7, 'O');
insert into toto values (7, 'U');
insert into toto values (8, 'O');
insert into toto values (9, 'U');
insert into toto values (9, 'O');
insert into toto values (9, 'I');
insert into toto values (9, 'L');
insert into toto values (9, 'U');
insert into toto values (9, 'O');
insert into toto values (9, 'I');
insert into toto values (9, 'L');
insert into toto values (9, 'U');
insert into toto values (9, 'O');
insert into toto values (9, 'I');
insert into toto values (9, 'L');
I want where flag is 'U' or 'O' or 'U' and 'O' they should be mark as 'SAT' and those who are
having flag 'U' and 'O', and 'I' and 'L' should come as present
my output should be
1 SAT
2 SAT
3 SAT
4 PRESENT
5 SAT
6 SAT
7 SAT
8 SAT
9 PRESENT
pl show me how to do it
thanks
deveshHi, Devesh,
user10745179 wrote:
Hi,
I am having following data in Oracle 9i
create table toto ( a number, flag varchar2(1));
insert into toto values (1, 'U');
insert into toto values (1, 'O');
insert into toto values (2, 'U');
insert into toto values (3, 'U');
insert into toto values (3, 'O');
insert into toto values (4, 'U');
insert into toto values (4, 'O');
insert into toto values (4, 'I');
insert into toto values (4, 'L');
insert into toto values (5, 'U'); ...Thanks for posting the CREATE TABLE and insert statements; that's very helpful.
I want where flag is 'U' or 'O' or 'U' and 'O' they should be mark as 'SAT' and those who are
having flag 'U' and 'O', and 'I' and 'L' should come as present
my output should be
1 SAT
2 SAT
3 SAT
4 PRESENT
5 SAT ...It looks like you're using "having" to mean two different things.
Are you saying that, for a group (all the rows with the same value of a) to be called 'PRESENT' it must have all 4 values 'U', 'O', 'I' and 'L', but to be marked as SAT it only needs to have 1 of the values 'O' or 'U' (e.g., a=2 has only 'U')?
Here's one way:
SELECT a
, CASE
WHEN COUNT ( DISTINCT CASE
WHEN flag IN ('I', 'L', 'O', 'U')
THEN flag
END
) = 4
THEN 'PRESENT'
WHEN COUNT ( DISTINCT CASE
WHEN flag IN ('O', 'U')
THEN flag
END
) >= 1
THEN 'SAT'
END AS flag_summary
FROM toto
GROUP BY a
ORDER BY a
;Are 'I'. 'L', 'O' and 'U' the only possible values of flag? What happens if a group has flags other than the 4 you mentioned?
Edited by: Frank Kulash on Dec 1, 2011 6:59 AM -
What value for parameter Workspace when run function RSAQ_DELETE_QUERY?
Run function RSAQ_DELETE_QUERY to delete a query, it requires to input a Workspace value, what's that? and which value we should input for this parameter Workspace?
ThanksHi Kevin,
I think you can just leave it space. In the popup, don't enter a value and press enter.
Siggi
PS: Don't forget, this is not a tested solution.
Message was edited by: Siegfried Szameitat
Maybe you are looking for
-
I have a problem in using Safari on my Ipad 3. Every time I access to my gmail, then the Safari start blinking can't open my mail. It happen After I updated to ios6. Thank you for your help.
-
Sorting A Table Based on single Column
Hi, I wrote the piece of code to sort a webdynpro Table. wdContext.nodeKMAccess().sortElements( new Comparator() public int compare(Object x, Object y) int iX,iY; IPrivateDownloadKMHitsReportView.IKMAccessElement rx = (IPrivateDow
-
Can't connect to WiFi after OS update and reboot of Playbook
Phoned RIM Support, and was advised it is a known problem, and our best people are working on it. Not sure how they will communicate fix to a device that may be corrupted.
-
I am getting duplicates when I import from my memory card. I have the settings in Elements 12 set to not import duplicates. They are named with a -1
-
Photoshop install folder.
I change the install folder, but don't let me install cause say this : ERROR: DW041: INSTALLDIR Volume F:\ doesn't exist. That folder doesn't exist, and i can't change it.