query or pl sql block to display the mentioned result
create table shirt (color varchar2 (10), number Qty., number s, number m, l, xl, xxl number);
insert into shirt values ('black', 10, 5,2,1,2,0);
insert into shirt values ('black', 8, 2,1,2,0,3);
insert into shirt values ('White', 5, 2,1,1,0,1);
insert into shirt values ('White', 7, 2,1,2,1,1);
How to get the bottom of output?
Expected result:
G1 G2 QUANTITY
Black s 7
Black 3 m
Black l 3
XL Black 2
XXL black 3
White s 4
White m 2
white l 2
XL white 1
White xxl 2
Vinodh
Correction
with
shirt as
(select "black" color, quantity 10, 5 s, 2 m, 1 l, 2-xl, xxl 0 of all the double union)
Select 'Black', 8, 2, 1, 2, 0, 3 double Union all
Select 'White', 5, 2, 1, 1, 0, Union 1 double all the
Select 'White', 7, 2, 1, 2, 1, 1 double
)
Select the color of g1, g2, quantity
(select color, concerned, sum (m) m, sum (l) l, sum (xl) xl, sum (xxl) xxl
shirt
Group by color
)
UNPIVOT (quantity for g2 in (as ', m mod', 'l' l, xl as "xl", xxl as a 'xxl'))
order of g1, decode(g2,'s',1,'m',2,'l',3,'xl',4,'xxl',5,6)
G1 | G2 | QUANTITY |
---|---|---|
Black | s | 7 |
Black | m | 3 |
Black | l | 3 |
Black | XL | 2 |
Black | XXL | 3 |
White | s | 4 |
White | m | 2 |
White | l | 3 |
White | XL | 1 |
White | XXL | 2 |
Concerning
Etbin
Tags: Database
Similar Questions
-
BI Publisher - block entity - display the global attributes
Hello
With the help of OPA 12.2.1.
I use an rtf to generate a PDF file at the end of my interview.
In the rtf, I have a block of an entity:
<? for-each: children? >
<? end foreach? >
In this block, I display the attribute of the entity, but I view the global attributes so for each child.
Behavior: the child attributes are displayed, but not overall.
For the record, the global attributes are well displayed outside teaching.
No idea what to do?
Thank you.
Orlando
The exact path of the child elements being processed at the global attribute is not just "... / ' could be several levels upward. The XML being processed by BI publisher can be considered to be a file path (in XML called XPath) each subelement is 'low' level and each parent elements is "up" one level (for example "..") ("/" current level is the parent). The key is to look at the real generated XML and then determine the best way to access the elements in your RTF. XPath is very powerful to navigate anywhere in the XML document to select the nodes/elements that you want to process. Resources such as the https://blogs.oracle.com/ocsbip/entry/xslxsltxpathxslfo_part_1 can explain more in detail.
-
SQL: how to display the second string of the function in the Jobs table only if the function has more than one string.
Hello
You can use REGEXP_SUBSTR Oracle/PLSQL: REGEXP_SUBSTR function
Select the function double REGEXP_SUBSTR('PUBLIC RELATION REPRESENTATIVE ','[^]+',1,2);
Do you have any value of the column as no 2nd string?
-
Hello!
I have a simple object type and a proecdure in which I am trying to use it to insert into another table
-object
CREATE ORREPLACETYPEmt_mtg ASOBJECT
(
ACOL NUMBER ,
BCOL NVARCHAR2 (100)
);
CREATE ORREPLACETYPEREF_MTG ASTABLEOFMt_MTG ;
-same structure as the use of sampletbl target table in the cursor query
create table tbl_MT_MTG
(
ACOL NUMBER ,
BCOL NVARCHAR2 (100)
);
-procedure
CREATE ORREPLACEINTERIORTEST_PROCEDURE1
AS
ref_cur sys_refcursor ;
REFR ref_mtg ;
BEGIN
OPEN ref_cur FOR
Select acol,
BCOL
DE sampletbl où rownum<10;
Fetch ref_cur in bulk collectintorefr;
Insert intotbl_MT_MTG(acol,bcol)selectacol,bcol fromtable(refr);
commit;
CLOSE Ref_cur;
END;
/
When I run this procedure fails with
ORA-06504: PL/SQL: return variables of the game results or the query types do not match
ORA-06512: at "TEST_PROCEDURE1", line 10
ORA-06512: at line 2
Any help on this please...
Thanks to an OLD POST below
so perfect helped me! Thank you
Tubby
After 5 years of more :-)
How to store refcursor in collection How to store refcursor in collection
-
Help of query SQL - inner joins and the separate results
Hello
ASP VB, SQL Server
I have a structure of data base with 3 tables - users, albums and photos. each user has a identifier unique, each record has a unique albumid and also contains a column with the user name. each record in the photo has a unique id so that store the user name and the album in which the image belongs.
I'm writing a query that returns a list of the albums for a particular user (based on a user name query string) and who will also bring back the id of the first record in the table for each of these albums photo.
the closest I get is to run a query to select albumid albums where userid = varuserid with a join internal on the pictures table to remove the photo ID - problem I then it comes out all the photos from the photos table where userid = varuserid, so when I do a repeat region to display a list of albums for a certain user It produces a list of all the photos where userid = varuserid
I really want to return just a list of ID album based on the username variable, but also to return the first record in the table of photos for each of these albumids
I tried different combinations of inner joins, select distinct etc but no joy.
any suggestion would be appreciated as am floundering here...
First, you must define 'first' with regard to the photos. Is there a
timestamp? They are numbered inside the album? Do you really care who is
"first", or do you want simply a shot? You also neglected to indicate if they are
empty photo albums have been allowed. I assumed that the empty albums are not
allowed.Whatever you decide, the answer will be similar.
SQL Server tends to get better results with joins with subqueries. You will have
See such a written request more often with subqueries, and there isn't
nothing wrong with that, but I'll use a join on a derived table. I have
have not all column names (hint, hint), so I made them, but the
Comments should help out you.SELECT A.Title, P.PhotoID, P.Caption, A.AlbumID, P.ImagePath
FROM dbo. A albums
-build a table derived, consisting of photo ID lowest for each
album.
INNER JOIN (SELECT AlbumID, MIN (PhotoID) AS FirstPhoto FROM dbo. Photos
AlbumID GROUP) AS PM WE A.AlbumID = PM. AlbumID
-details of the photo for the photo shown in the table above
INNER JOIN dbo. Photos P on A.AlbumID = P.AlbumID AND
H. FirstPhoto = P.PhotoID
User A.UserID ='some WHERE '"tedstar" wrote in message
News:ee4pfn$de$1@forums. Macromedia.com...
> I am writing a query that returns a list of the albums for a
> particular user (based on a user name query string) and also bring
> return
> the id of the first record in the table for each of these albums photo. -
to change the pl/sql block to get the value of the user
In this code rather than affect the value of the SID in the block, I want to get the sid of the user.
Help, please.
Oracle Database 10 g Express Edition Release 10.2.0.1.0 - product PL/SQL Release 10.2.0.1.0 - Production CORE 10.2.0.1.0 Production AMT for 32-bit Windows: Version 10.2.0.1.0 - Production NLSRTL Version 10.2.0.1.0 - Production declare
v_sname t1.sname%type;
v_issue_date t3.issue_date%type;
v_book_title t2.book_title%type;
v_book_id t2.book_id%type;
cursor c1 is
Select t1.sname, t3.issue_date, t2.book_title, book_id
join T1 T3
using (SID)
Join t2
using (book_id)
where sid = 1;
Start
Open c1
loop
dbms_output.put_line (v_sname |) » ' || v_issue_date | » ' || v_book_title | ' ' || v_book_id);
extract the c1 in v_sname, v_issue_date, v_book_title, v_book_id;
When exit c1% notfound;
end loop;
Close c1;
end;
/
Thank you
If I set up a script that I want to pass a value, I just a configuration variable and name it and use it very similar to a procedure or function. Makes it easy to implement a procedure/function, or to convert a function/procedure in a PL/SQL block for test/debugging with relatively few changes to the code inside:
declare in_sid number := to_number('&1'); v_sname t1.sname%type; v_issue_date t3.issue_date%type; v_book_title t2.book_title%type; v_book_id t2.book_id%type; cursor c1 is select t1.sname, t3.issue_date, t2.book_title, book_id from t1 join t3 using(sid) join t2 using(book_id) where sid=in_sid; begin open c1 loop dbms_output.put_line( v_sname ||' ' || v_issue_date ||' ' || v_book_title || ' ' || v_book_id); fetch c1 into v_sname, v_issue_date, v_book_title, v_book_id; exit when c1%notfound; end loop; close c1; end; /
-
% ROWCOUNT SQL does not return the expected result
I have the following function within a package:
--Update APPERY_JTI_deleted_USERS table: FUNCTION fn_updt_app_jti_dlt_usr( p_update_co IN VARCHAR2, p_appery_user_id IN APPERY_JTI_deleted_USERS.appery_user_id%TYPE, p_outlet_code IN APPERY_JTI_deleted_USERS.outlet_code%TYPE) RETURN NUMBER AS lv_sql VARCHAR2(4000); lv_rowcount NUMBER := 0; BEGIN lv_sql := 'UPDATE APPERY_JTI_deleted_USERS SET '||p_update_co||' = 1 WHERE '||p_update_co||' = 0 AND OUTLET_CODE = '''||p_outlet_code||''' AND APPERY_USER_ID = '''||p_appery_user_id||''''; --EXECUTE IMMEDIATE lv_sql; EXECUTE IMMEDIATE 'BEGIN ' || lv_sql || '; :z := sql%rowcount; END; ' USING OUT lv_rowcount ; RETURN lv_rowcount; EXCEPTION WHEN OTHERS THEN RETURN -1; END fn_updt_app_jti_dlt_usr;
The function called several times as part of a job. Basically, the main function (Say M), call a few functions (for example A1... A9). Each of these functions is to do something and updated the application using the above function. Therefore, each of the nine functions will call the above function with different parameters.
The problem that I am facing is:
First run, invoke only first of all for the above function will return the positive result ($sql rowcount > 0). When I run M the second time, only first and second calls for the above function will be to return positive results and so on.
How odd, it's that if I change the values again and run a function M, it will start from the beginning. And what strange more, the dynamic update statement is executed correctly and data are updated successfully. It's just sql rowcount % do not return is not the expected results.
I tried to run execute immediately without (begin, end). I also tried to run it without HELP ON. It's always the same. I'm really confused, what Miss me here.
I don't know if this is relevant. But for what it's worth, invoking the function above updates the SAME lines in the table appery_jti_deleted_users that the columns are different. So for all the work, the same lines need to be updated. Each function (A1... A9) will call the above function to update a different column of these lines.
If you REALLY want to help you having US SHOW, not tell us:
1. WHAT you do
2. HOW to
3. WHAT results you get
4. WHAT results you expect to get
First run, invoke only first of all for the above function will return the positive result ($sql rowcount > 0). When I run M the second time, only first and second calls for the above function will be to return positive results and so on.
How odd, it's that if I change the values again and run a function M, it will start from the beginning. And what strange more, the dynamic update statement is executed correctly and data are updated successfully. It's just sql rowcount % do not return is not the expected results.
Perhaps that the foregoing is true and maybe he's not. We have NO WAY of knowing because you don't SHOW US anything.
I tried to run execute immediately without (begin, end). I also tried to run it without HELP ON. It's always the same.
Yet once you showed us NOTHING >
You do NOT FOLLOW best practices when you use dynamic sql statements: the sql statement real so that you can print:
1 SEE what's running - make sure there are no syntax errors, and it seems to be what you wanted
2 EXECUTE/TEST manually - to see if he really runs without error and see what results it really give.
3. FIX any syntax or other problems and retest it
Instrument properly your code and you won't have the problems you are having.
You should know by now what are the parameters are transmitted when you run the function. So, there are at least three sets of these parameters.
So you should be able to:
1 run the instrumented manually function three times
2. see that all three SQL statements are
3 manually run these instructions
4. see that the number of lines is after each execution
We have no idea of what the output of the function is every time you call it. Apparently, you have, if you save the results of the function somewhere, but you didn't post any of this info.
We need real details to help you - just listen to your story is not enough.
-
Hi Experts,
I have a DB table has columns of more than 50.
I question this table, it should only return one line at any time. as sqldeveloper below image.
here, I need to build block pl/sql-query, Discover the column in the table as a key and query result as values.
Eg: Key - Value
TASK_EVENT_ID - 1765
EVENT_TYPE - ASR_UPDATE
... etc until all of the columns in my table.
Experts please comment on that point, appreciate your help on this.
Thank you
-Vincent.
Here is an approach using DBMS_SQL to iterate over the columns of key / value to assign... (Little code snipped for brevity)
create or replace procedure (task_expired)
v_store_id in full,
v_task_action_id in full,
v_job_id in full
)
as
-[SNIP code...]
v_sql VARCHAR2 (4000): = ' select * from my_table where PK = 123'; -Your SQL here!
v_v_val VARCHAR2 (4000);
v_n_val NUMBER;
v_d_val DATE;
v_ret NUMBER;
c NUMBER;
d NUMBER;
col_cnt INTEGER.
f BOOLEAN;
rec_tab DBMS_SQL. DESC_TAB;
col_num NUMBER;
vAsString VARCHAR2 (4000);
BEGIN
-[SNIP code...]
Message_properties. CORRELATION: = "EDF_EVENT";
MSG: = SYS. AQ$ _JMS_BYTES_MESSAGE. Construct();
Msg.set_string_property ('queueName', ' shipping/csi_cth');
Msg.set_string_property ('MODE', 'CR8');
c: = DBMS_SQL. OPEN_CURSOR;
DBMS_SQL. PARSE (c, v_sql, DBMS_SQL. NATIVE);
d: = DBMS_SQL. Execute (c);
DBMS_SQL. DESCRIBE_COLUMNS (c, col_cnt, rec_tab);
1.col_cnt J
LOOP
CASE rec_tab (j) .col_type
WHEN 2 THEN
DBMS_SQL. DEFINE_COLUMN (c, j, v_n_val); -Number
WHEN 12 CAN
DBMS_SQL. DEFINE_COLUMN (c, j, v_d_val); -Date
ON THE OTHER
DBMS_SQL. DEFINE_COLUMN (c, j, v_v_val, 2000); -Else treat as varchar2
END CASE;
END LOOP;
LOOP
v_ret: = DBMS_SQL. FETCH_ROWS (c);
WHEN OUTPUT v_ret = 0;
1.col_cnt J
LOOP
-Fetch each column to the correct data type based on coltype
CASE rec_tab (j) .col_type
WHEN 2 THEN
DBMS_SQL. COLUMN_VALUE (c, j, v_n_val);
vAsString: = to_char (v_n_val);
WHEN 12 CAN
DBMS_SQL. COLUMN_VALUE (c, j, v_d_val);
vAsString: = to_char (v_d_val, ' DD/MM/YYYY HH24:MI:SS');
ON THE OTHER
DBMS_SQL. COLUMN_VALUE (c, j, v_v_val);
vAsString: = v_v_val;
END CASE;
Msg.set_string_property (rec_tab (j) .col_name, vAsString);
END LOOP;
END LOOP;
DBMS_SQL. CLOSE_CURSOR (c);
DBMS_AQ. ENQUEUE (queue_name-online 'cbus.aqjms_common',
Enqueue_options => Enqueue_options,
Message_properties => Message_properties,
Payload-online msg,
Msgid => Message_handle);
dbms_output.put_line ('00 Msgid =' |) Message_handle);
dbms_output.put_line('===Done=');
-[SNIP code...]
END;
/
-
A hierarchical report query SQL formatting to display the output as a tree
4.2.1
THM:2
Hello world
I have a simple request which when I run it should show in a tree like structure as seen in this link
Hierarchical queries in Oracle SQL
Any ideas on how I can get this output show upward in an area of report page apex? I tried to put it in a classic report, and it shows just all in one line given the length and spacing. I don't want to use the tree for this.
Thank you!
Ryansun-Oracle wrote:
I have a simple request which when I run it should show in a tree like structure as seen in this link
Hierarchical queries in Oracle SQL
Any ideas on how I can get this output show upward in an area of report page apex? I tried to put it in a classic report, and it shows just all in one line given the length and spacing. I don't want to use the tree for this.
I found that the standard reports and report templates are not really useful in this situation.
According to exactly how it should be used, you might want to watch a dynamic list using one of the models of hierarchical list, but I tend to use this Tyler Muth & Rob Van Wijk. This can be used in a region in connection with a column named custom report template.
-
Retrieve data from PL/SQL block and generate the UNIX data file
Hi all
I comply the following Unix Shell Script code block. The following code was generated the file count_curdate.txt with all need info. The query gives the number of records, the partition_dt group
ABC ='sqlplus-s < < of folklore > count_curdate.txt
uname/paswd@ConnectString
SET THE OFF POSITION;
SELECT COUNT (*) | «, » || partition_dt of the XYZ group by partition_dt;
"exit";
END '
But now I need to change the above code to use dbms_application_info.set_module in it. Could someone let me know how to generate the file using PL/SQL in Shell Script block. I have tried following written code, but it generates count_curdate.txt file with 0 bytes.
ABC ='sqlplus-s < < of folklore > count_curdate.txt
uname/paswd@ConnectString
Set serveroutput on;
SET THE OFF POSITION;
Set feedback off;
BEGIN
DBMS_APPLICATION_INFO.set_module (' shm.ksh ',' get account per day ");
FOR again IN (SELECT COUNT (*):) «, » || partition_dt as 'DCount"of the XYZ of partition_dt group);
LOOP
DBMS_OUTPUT. Put_line (reccur. DCount);
END LOOP;
end;
/
"exit";
END 'Hello, your PL/SQL is not successfully completed, i.e.,.
This:
ABC=`sqlplus -s <
count_curdate.txt uname/paswd@connectstring set serveroutput on; SET HEADING OFF; set feedback off; BEGIN dbms_application_info.set_module ('shm.ksh','get count by day'); FOR reccur IN (SELECT COUNT(*)||','||partition_dt as "dcount" from XYZ group by partition_dt); LOOP DBMS_OUTPUT.PUT_LINE(reccur.dcount); END LOOP; end; / exit; END` Should be this:
ABC=`sqlplus -s <
count_curdate.txt uname/paswd@connectstring set serveroutput on; SET HEADING OFF; set feedback off; BEGIN dbms_application_info.set_module ('shm.ksh','get count by day'); FOR reccur IN (SELECT COUNT(*)||','||partition_dt as "dcount" from XYZ group by partition_dt); LOOP DBMS_OUTPUT.PUT_LINE(reccur.dcount); END LOOP; end; / exit; EOF` -
Hi all
We have an obligation to state the previous year, current year and values of the year next as a LOV in the ADF page.
This is the query that retrieves the previous year, current year and next year. But the result of this query displays values in 3 columns:
Select (Extract(year from sysdate)-1), extract (year sysdate), (extract (year sysdate) + 1) twice;
Output:
2012 2013 2014
But I want to display them in a single with 3 rows as column:
2012
2013
2014
Please your ideas.
or in the same way
SELECT EXTRACT (YEAR FROM ADD_MONTHS (SYSDATE, 12 *(LEVEL-2)))
OF the double
connect by level<>
-
Command SQL PLUS to display the size of the data file
How can I know my tables disk space after insertion of data
Thank youHello
Did you do the space occupied by the tables in the database.
If Yesselect sum(bytes)/1024/1024, segment_name from dba_segments group by segment_name or select sum(bytes)/1024/1024 from dba_segments where segment_name = 'Table_name'
Or have you served the space occupied by the data files
select bytes/1024/1024, file_name from dba_data_files;
Concerning
Anurag -
I do not change my Google settings. I've always had it ready to open search results in a new window. Some time before, he began to open two windows that have the same url/content.
This problem may be caused by an extension that is not working properly.
Start Firefox in Firefox to solve the issues in Safe Mode to check if one of the extensions or if hardware acceleration is the cause of the problem (switch to the DEFAULT theme: Firefox/tools > Modules > appearance/themes).
- Makes no changes on the start safe mode window.
- https://support.Mozilla.org/KB/safe+mode
-
I want to format below
Name of the parameter
Protocol 1 read value
Protocol 2 reading value
Result
Range of report generation have MANY functions for working with tables, including HTML. By the way...
Example of a linked table.
-
Confirmation of dashboard does not display the desired results
Hello
I have confirmation created using this condition. But it does not show me the results. The code seems to be correct.any help please...
-case when TimeStampDiff (SQL_TSI_DAY, "TB1". CL1, CURRENT_DATE) between 0 and 30 or TimeStampDiff (SQL_TSI_DAY, "TB1". Cl2, CURRENT_DATE) between 0 and 30, then 30 days
When TimeStampDiff (SQL_TSI_DAY, "TB1". CL1, CURRENT_DATE) between 31 and 60 or TimeStampDiff (SQL_TSI_DAY, "TB1". Cl2, CURRENT_DATE) between 31 and 60 then "60 days".
When TimeStampDiff (SQL_TSI_DAY, "TB1". CL1, CURRENT_DATE) between 61 and 90 or TimeStampDiff (SQL_TSI_DAY, "TB1". CL1, CURRENT_DATE) between 61 and 90 ' last 90 days.
another end '> 90 and max 100 days '.Hello
Create a dummy column for the code below
case when TimeStampDiff(SQL_TSI_DAY,"TB1".CL1,CURRENT_DATE) between 0 and 30 or TimeStampDiff(SQL_TSI_DAY,"TB1".CL2,CURRENT_DATE) between 0 and 30 then '30 days' when TimeStampDiff(SQL_TSI_DAY,"TB1".CL1,CURRENT_DATE) between 31 and 60 or TimeStampDiff(SQL_TSI_DAY,"TB1".CL2,CURRENT_DATE) between 31 and 60 then ' last 60 days' when TimeStampDiff(SQL_TSI_DAY,"TB1".CL1,CURRENT_DATE) between 61 and 90 or TimeStampDiff(SQL_TSI_DAY,"TB1".CL1,CURRENT_DATE) between 61 and 90 then 'last 90 days' else '> 90 and max 100 Days' end
filter as is invited for this column after that giving filter as it is prompting you can hide this column or remove it.
Save the report
Award points and to close the debate, if your question is answered.
See you soon,.
Aravind
Maybe you are looking for
-
Tecra M11 - 103 accupoint 2 double-click randomly instead of 1-click
I get an annoying problem whem, click the left accupoint button, designated as the 'click' in the accupoint settings. He sometimes of doubleclick instead. someone has experienced this problem? found a solution?
-
DV6929NR backlight isn't on.
Hello I got this laptop for Christmas from my grandparents and have been using it frequently. I started it this morning with no problems, the screen is very bright, as if it were usually. I closed it to say things to save energy while it was plugged,
-
PID Setpoint profile using Minutes instead of seconds
The standard input for the PID setpoint profile VI is in seconds. Is there a way to change this so that you can enter a profile in minutes?
-
As the administrator of my computer, I created a user password recently for safety because my girls using my computer and I don't want to have administrative privileges. I write my password down and created a secret hint, but my password does not wor
-
Device base system &; coprocessor problem with driver Windows 7 - Pavilion dv9720us
I have a HP Pavilion dv9720us which was very glitch with Vista 32 bit. After saving all on an external hard drive from Seagate Replica, I did a clean install of Windows 7 64-bit. Everything seems to work, but I get error messages stating that the x