Query Results pl sql
I am having a problem in appending various coulomns into one row. I will explain by illustrating an example.
Suppose I have a table "student." I have used dots to separate the fields.
St_id st_no st_sub
1........1........A
2........1........B
3........1........C
4........2........A
5........2........B
I want the output in the following format -
St_id....st_no... st_sub
1,2,3.......1........A,B,C
4,5.........2........A,B
Please let me know how to code this and obtain an output for the same. Thanks a bunch in advance
Found this on:
http://asktom.oracle.com/pls/asktom/f?p=100:11:2119231749211243::::P11_QUESTION_ID:229614022562
So: You'd need to create your own function here.
I must say that I'm truly amazed how Tom solved this almost 10 years ago (never stumbled on that link before), incredible!
Only change I made to the original example from Tom was having your separator as a parameter (default value = a comma) instead of hardcoding it.
So: this should work for you on 8i:
MHO%xe> create table student as ( --generating sample data:
2 select 1 st_id, 1 st_no, 'A' st_sub from dual union all
3 select 2,1,'B' from dual union all
4 select 3,1,'C' from dual union all
5 select 4,2,'A' from dual union all
6 select 5,2,'B' from dual
7 );
Tabel is aangemaakt.
MHO%xe> select * from student
2 /
ST_ID ST_NO ST_SUB
1 1 A
2 1 B
3 1 C
4 2 A
5 2 B
MHO%xe> create or replace
2 function transpose( p_key_name in varchar2,
3 p_key_val in varchar2,
4 p_other_col_name in varchar2,
5 p_tname in varchar2,
6 p_sep in varchar2 default ','
7 )
8 return varchar2
9 as
10 type rc is ref cursor;
11 l_str varchar2(4000);
12 l_sep varchar2(1) := p_sep;
13 l_val varchar2(4000);
14
15 l_cur rc;
16 begin
17
18 open l_cur for 'select '||p_other_col_name||'
19 from '|| p_tname || '
20 where ' || p_key_name || ' = :x '
21 using p_key_val;
22
23 loop
24 fetch l_cur into l_val;
25 exit when l_cur%notfound;
26 l_str := l_str || l_sep || l_val;
27 end loop;
28 close l_cur;
29
30 return ltrim(l_str, l_sep);
31 end;
32 /
Functie is aangemaakt.
MHO%xe> select transpose( 'st_no', st_no, 'st_id', 'student' ) st_id
2 , t.st_no
3 , transpose( 'st_no', st_no, 'st_sub', 'student' ) st_sub
4 from student t
5 group by t.st_no;
ST_ID ST_NO ST_SUB
1,2,3 1 A,B,C
4,5 2 A,BBut you really should want to upgrade to a more recent (and supported) DB-version, it will make your life better ;)
Similar Messages
-
Edit query results in SQL worksheet
I can't edit query results in SQL worksheet, I not found any options to "ON" this. I use SQL Developer 2.1.1.64.
You can't edit results in the worksheet. It's an accepted feature request with no scheduled date. In the mean time you have to go to the table or write an update statement.
-
Output query results in sql transaction code
Is the code below valid? I think the comma at the end of my
variable is
throwing an error when I run this.
Eg. "#trim(product)#",
I need the comma however to make the statement correct except
after the last
record. Is there any way around that?
<cfquery name="calc" datasource="#client.dsn#"
username="#client.username#"
password="#client.password#">
SELECT *
FROM order_history
WHERE OrderNo='823719'
AND product in (<cfoutput
query="backorders">"#trim(product)#",</cfoutput>)
AND invoice < #max.invoice#
ORDER BY invoice desc
</cfquery>since it looks like you are dealing with strings, take a look
at the
QuotedValueList function.
hth
Tim Carley
www.recfusion.com
[email protected] -
Hi- I occasionally come across this issue when I run any query in SQL Developer (3.0.02), the Query Result tab shows a bold red Exclamation point and the display grid is blank. It says "Fetched 50 rows in 0.235 seconds" but the results aren't displayed. There is nothing wrong with the queries so it seems like some type of display problem but I can't figure out how to fix it. Like I said, it doesn't happen all the time and I run the same saved queries so I know it's not a problem with the actual queries. Has anyone ever seen or heard of this before?
Hi,
Sounds like you are using an early adopter version of 3.0. Why not upgrade to the latest production release (3.1.07.42)?
A similar situation is described in this old thread:
Re: Randomly not getting query results
Regards,
SQL Developer Team -
SSMS Addin - How To Access Query Results Grid
Hi,
I want to access Query Result Grid(Results) in SSMS addin but I did'nt found anything.
How can I access Query Result Grid, Rows, Columns and Cells when I executed a script?
Thanks.SQL Server Management Studio currently supports query execution results to be displayed in three different ways: Results to Grid,
Results to Text and Results to File.
By default SQL Server Management Studio is configured to display query results in
Grid format. If you want to change the default to some other option follow these steps.
1. In SQL Server Management Studio, under Tools menu, click
Options as shown in the snippet below.
2. In the Options dialog box, expand Query Results, expand
SQL Server and then select General as shown in the snippet below. In the right side panel choose one of the three options shown below in the
Default Destination for results drop down list and click
OK to save the changes as shown in the snippet below. The changes will go into effect once you open a New Query window.
Query Result Options for Results to Text
In this format you have the option to display the results in a different tab as well as setting different output options.
In the Options dialog box, expand Query Results, expand
SQL Server and then select Results to Text tab as shown in the snippet below. In the right side panel first select the checkbox for
Display results in a separate tab and then select the checkbox for
Switch to results tab after the query executes and then click
OK. If you would like to also display the column name in the result set then choose the option Include column headers in the result set
as shown in the snippet below.
The options you can use in the Text format are:
Output format: - In the above snippet you could see that by default the output is displayed as columns aligned. Some of the other options that are available are Comma Delimited,
Tab Delimited, Space Delimited and Custom Delimited. If you choose the Custom Delimited option in the Output format drop down list then you need to specify a character of your choice for the delimiter in the
Custom delimiter text box.
Include column headers when copying or saving the results: - If this option is selected, then whenever the results are copied to clipboard or it is saved to a file the column headers are also copied along with the results.
Include the query in the result set: - The text of the query is displayed as part of query output under the messages tab.
Scroll as results are received: - If this option is selected, then the display focuses on the most recently returned records at the end of the results set.
Right align numeric values: - If this option is selected, then numeric values will be aligned to the right of the column.
Discard results after query executes: - If this option is selected, then the query results are not displayed in the reviewing pane.
Display results in a separate tab: - If this option is selected, then the result set after query execution will be displayed in a new tab instead of at the bottom of the query window.
Switch to results tab after the query executes: - If this option is selected, then after the query execution the screen focus will be set to the results tab.
Maximum number of characters displayed in each column: - This sets the maximum characters to display for any one column. So if you have a column that is 500 characters this will only show the first 256 if you keep the default setting.
Ref link :http://www.mssqltips.com/sqlservertip/2346/different-options-for-query-results-in-sql-server-management-studio/
Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/ -
Getting query results from a PL/SQL procedure
Hi! So, I’m a little stumped and I can’t seem to find the answer to what I believe is probably a simple question…
So, here goes… I have a big ol’ union query that I use to create a report on a page, it’s about 25k – not over the 32k limit, but fails to be able to compile every time (I always get a 400 – Bad Request error). I’m not sure why this is happening, but I can remove a union statement and it compiles just fine – so it has something to do with the size of the query. ANYWAY – I’ve resolved that I should put this bad boy into the database as a stored procedure and just call it from Apex, my problem is I can’t figure out quite how to do this with variables, etc.…
Instead of giving you my whole big query, I’ll use the emp table as the concept is the same:
Say we have a query that creates a report on a page:
select empno, ename, job, mgr, hiredate, sal, comm, deptno
from emp
where job = :P_JOB
and hiredate >= :P_HIREDATE;
How would I take this query, create it as a stored procedure on the db, pass the variables from Apex and return the query result set from the stored proc as a report?
I really appreciate any help on this!
Best,
GilcrestHi Gilcrest,
You should create the query as a View and use the view name and the WHERE clause in the report's sql source.
Andy -
Sending email using PL/SQL based on a query result
Hello all,
I want to create a procedure using PL/SQL, based on a query result.Here is the scenario:
I have multiple tables in Target and Source databases that I want to compare(not the whole table but queries on these tables) and if they differ, I want to shoot an email. I have some ideas how to implement this but not sure whether it is the best approach.
select Acct_id, total from SourceTableA
minus
select Acct_id, total from TargetTableA
select Acct_id, sum from SourceTableB
minus
select Acct_id, sum from TargetTableB
If the result of any of above queries > 0 then I want to shoot an email and want to repeat this procedure in the morning every day.
I know how to implement send_mail procedure using UTL_SMTP package and how to schedule tha job by dbms_job package. But I am not sure how to implement the result of minus query. In case if minus > 0 then I also want to send the name of tables in the email message where source and target tables are not same. Should i use cursor, variable or insert the result in a new table? any help would be highly appreciated. Thanks in advance.
KhanActually these queries are the part of our daily testing that we run everyday manually(after the scheduled ETL load) to see if there are any discrepencies between our datawarehouse tables and source tables. So instead of running these queries manually everyday we want to schedula a procedure that will shoot an email in case of any discrepency and indicate which tables have problems.
-
How to compare result from sql query with data writen in html input tag?
how to compare result
from sql query with data
writen in html input tag?
I need to compare
user and password in html form
with all user and password in database
how to do this?
or put the resulr from sql query
in array
please help me?Hi dejani
first get the user name and password enter by the user
using
String sUsername=request.getParameter("name of the textfield");
String sPassword=request.getParameter("name of the textfield");
after executeQuery() statement
int exist=0;
while(rs.next())
String sUserId= rs.getString("username");
String sPass_wd= rs.getString("password");
if(sUserId.equals(sUsername) && sPass_wd.equals(sPassword))
exist=1;
if(exist==1)
out.println("user exist");
else
out.println("not exist"); -
I tried to make the question as explicit as possible.
Refer to Sql Server Management Studio's Results view. Depending upon the structure of the execution plan, the Results pane may begin displaying results while the query is still executing. Can someone point me in a direction for architecting a
data layer (I am tech and framework agnostic for this task. Any solution will suffice) that will begin receiving pages of the set before SQL Server has completed the entire query?
The call from the data layer to SQL Server will obviously have to be asynchronous, but is there any additional ceremony that I need to be aware of when issuing OPTION (FAST x) to the query optimizer?Thanks for the reply. (I actually meant to put this in the SQL Data Access forum, not the T-SQL forum)
"Generally the last step is ORDER BY in a
query, so nothing can start before that executes."
I would imagine you cannot ORDER BY and yield results as they are fetched because of the execution plan that would be generated. For the purposes of this post, please assume that sorting will be done purely client side
"Can you post your query?"
For purposes of discussion, let's assume that the query is
select *
from information_schema.columns
and also assume that you have "lots" of columns to display.
This was an exploratory question to see what would be necessary to replicate the behavior of Management Studio's Query Result view in a custom application.
I would imagine that there's going to be a lot of analysis of the execution plans that get generated in order for the OPTION (FAST x) optimizer hint to do any good, but apart from general tuning concerns that would allow SQL SERVER to yield a page of data
"fast", I was wondering if there was anything else required of the calling client to force it to yield return its first page.
After thinking about this (and phrasing it the way I did in the last sentence) perhaps this is the incorrect forum for this question. I imagine that my concerns are better addressed in forums dedicated to the technology of the calling client (which
would be a .NET assembly)
Be that as it may, if there is any ceremony that SQL Server imposes on clients in order to yield return, I would expect that my question would be in the scope of SQL Server discussions (even though I intended this to be in a different SQL Server forum) -
How to get the query result of improvement (Before and After ) using sql de
how to get the query result of improvement (Before and After ) using sql developer.
Check
http://www.oracle.com/technetwork/articles/sql/exploring-sql-developer-1637307.html -
2.1.0.62: Exporting query results does not work if SQL has a join
I get an error message, when I try to export the following test case to any data format.
create table test1 (id number(2), text varchar2(5));
create table test2 (id number(2), text varchar2(5));
insert into test1 values (1,'test');
insert into test2 values (1,'test');
select t1.*
from
test1 t1,
test2 t2
where
t1.id=t2.id;
I try to translate my german error message to english:
"There are no valid columns for export available. Clob- or Blob-Columns are currently not supported"
I get this message, when I right click into the query result grid and select export and then any data format.
Hope that is not a double post but searching for export did not find results for 2.1.
The following SQL also produces the error:
select t1.* from test1 t1;
These SQLs can be exported though:
select * from test1 t1;
select t1.id from test1 t1;
I should have mentioned that I work with Windows XP and Oracle 10.2.0.4.
Regards,
dhalek
Edited by: dhalek on Oct 13, 2009 5:04 PMHi,
Dhalek.
I've got the same problem here.
In my SQL Dev, I disabled the Autopopup code completion insight in SQL Worksheet. (Tools - Preferences - Code Editor - Code Completion - untick the checkbox). Restart SQL Dev. Tried to export a query.
The same error message appears.
My workaround is to re-enable the autopopup and restart SQL Dev.
The disabled autopopup code completion insight caused me these
2.1 EA1: Bugs - cannot Export Data from Grid
2.1 EA2: Bugs on code completion for displaying column name
Hope this helps,
Buntoro -
Hiding SQL statement in Query Result Window
Hi everyone,
Is it possible to hide the SQL statement from a query result window? This can usually be done by click the orange triangle that is positioned to the left of the SQL string box (to expand and collapse it). The System Queries have this box collapsed per default, is it possible to have this setup as default for all queries, including the custom? If so, please let me know where this can be done.
CheersYou should do this only with SDK programming - dont allow to show the syntax. The next, but problematic way, is the code you have do inside stored procedure and call only this sp inside the query generator window - if you have there some input parameters, you should use filling variables before executing sp and get it as input parameters to sp.
-
Store SQL query results in db table
Hi,
I have a SQL query that produces a report table.
Is it possible to automatically store the query results (or the report table) as a db table - without interrupting the current report building proces?
Thanks,
Dave
Message was edited by:
Dave JudgeHi Dave,
You can also insert records into an existing table:
INSERT INTO TABLEB (colA, colB, colC, etc) SELECT valA, valB, valC, etc FROM VIEWA WHERE etc etc
This can be done during a page process that runs "Before Header" and you can base your report on the TABLEB. Obviously, you will need to maintain that table to ensure that it is only truncated where necessary, that one user doesn't try to access another user's data on that table and that each time your page is loaded it doesn't try to repopulate the table when you don't need it to.
Another possiblity is to use a collection - which is user session based
Andy -
Query Results not coming for SELECT * in sql developer 3.1.07
VERY FRUSTRATING to use sql developer.
In SQL DEVELOPER 3.1.07:
WHAT WORKS: select sequence# from v$archived_log
WHAT DOESN'T WORK : select * from v$archived_log
You've got to be kidding me.
I wish I can show a screenshot, but can't in this forum. Here's my description:
When I run the query, in the bottom frame for Query Results, it just says: Executing: select * from v$archived_log in 0 seconds.
Then there's no result grid.
WOw>
This was when connected to a standby db that's in mount state
>
Is this a 'manual' standby db? Are you using Data Guard?
Post the results for what Gary ask of running the queries in sql*plus. If those queries give the same result then this is NOT a sql developer issue.
Review the following thread and post back with what information in it applies to your use case.
Re: V$ARCHIVED_LOG returns no rows on manual standby
If you are using Data Guard you may want to cross-post in that forum. -
Set Text Item To SQL Query Result
I am trying to set a text item to a SQL query result. Something like the following:
(I am trying to accomplish this in the SOURCE portion, set to 'SQL Query' source type, of the text item properties)
SELECT empno FROM emp WHERE empno = :SEARCH_EMPNO;
This only displays as the literal text when the application renders and not the value from the SQL query.
I apologize if this has already been posted but I could not find what I am looking for. I have seen posts that reference a pre-region computation but do not know the exact steps to accomplish the results I want.
Thanks in advance for anyone's time to help me with my issue.
KyleScott,
The literal that displayed (I have fixed it) was the actual SQL statement: SELECT empno FROM emp WHERE empno = :SEARCH_EMPNO;
I have resolved the issue, using SQL Query as the "Source Type" and Always, replacing any existing value in session state as the "Source Used" for the properties of the item.
What I was trying to accomplish is a search text item that would return the data for that record in a table into other text items, for each column in that record, for update; based on the search text item as a unique SQL query search for that record.
Thank you for your quick reply!
Kyle
Maybe you are looking for
-
Hi All, I inserted a record in ap_suppliers_int table and ran Supplier Open Interface Import. It is completed .. normal. But the status is REJECTED in ap_supllier_int with no values in reject_code and import_request_id. No entry in ap_supplier_int_re
-
Cant figure out whats wrong with my applet, help pls??
this applet checks a string against one in a database then if passwords match, a new url is opened. the applet loads in webpage with no problems. it just doesnt seem to work. have granted full access to code base in policy file. heres the code: impor
-
I cannot find a document I prepared yesterday. How do I locate it in the external backup disc
I cannot find a document I prepared yesterday. How do I locate it in the external backup disc
-
Button Toggle ADF Javascript(Works in Firefox but not in IE. why ?)
I have written a code to toggle button in ADF as follows: <af:resource type="javascript"> function enableDisable(actionEvent){ alert("21"); document.getElementById('cb1').style.background='red'; document.getElementById('cb2').style.background='green'
-
Using the Macbook Pro Internationally
So, I intend on moving to the Czech Republic, and have pretty much decided on buying the next version of the Macbook Pro (depending on how the prices are, anyway). I know that the laptop can take the voltages in Europe and that all I need is the plug