Select in PL/SQL
I have a select in a procedure with a multiple select option to "on"...or user can select multiple items....
I want to know which items user has selected....what is the best way to do it...
Thanks,
Harsimrat
It this what you are looking for?
create or replace package msw_pkg as
type array_type is table of varchar2(100) index by binary_integer;
v_arr array_type;
procedure msw1;
procedure msw2(pcourses in array_type default v_arr);
end msw_pkg;
show errors
create or replace package body msw_pkg as
procedure msw1 is
begin
htp.p('<form action="msw_pkg.msw2" method="post">
<select size="6" multiple name="pcourses">
<option value="1">opt1</option>
<option value="2">opt2</option>
<option value="3">opt3</option>
</select>
<input type="submit">
</form>
end msw1;
procedure msw2(pcourses in array_type default v_arr) is
begin
for i in 1..pcourses.count
loop
htp.p(pcourses(i));
end loop;
end msw2;
end msw_pkg;
show errors
Similar Messages
-
Using select * in pl/sql
Hi,
Yesterday Karthick mentioned that using SELECT * in PL/SQL is not a good idea. But I tried by creating a table and different procedures with selecting all columns using * and specifying the columns individually. Later I altered the table and both procedures became invalid. Can some one give a simple example to demonstrate the behaviour.
At present I dont have Oracle in my PC to post what I have tried yesterday.
Cheers,
SuriWhen I run the following script, the 2nd time the test1 procedure runs, it fails with "PLS-00905: object TEST1 is invalid", whereas test2 runs fine both times.
Feel free to try it yourself!
create table boneist_test (col1 number, col2 varchar2(10));
insert into boneist_test values (1, 'a');
commit;
create procedure test1
is
v_num number;
v_var varchar2(10);
begin
select *
into v_num, v_var
from boneist_test
where rownum = 1;
end test1;
create procedure test2
is
v_num number;
v_var varchar2(10);
begin
select col1, col2
into v_num, v_var
from boneist_test
where rownum = 1;
end test2;
begin
test1;
end;
begin
test2;
end;
alter table boneist_test add (col3 number);
begin
test1;
end;
begin
test2;
end;
drop table boneist_test;
drop procedure test1;
drop procedure test2; -
Select Expert or SQL Expression Fields help
I am trying to do something I would consider very simple but can figure it out.
I have two tables. FDC_Trips & Facility. On the report I can get the FDC_Trips.DivertedbyFacility field to populate a number value because that field is an integer. But we need the name to show up. That field is the ID (foreign key) of a Facilty which matches with the field Facility.Code. Instead of it displaying the DivertedbyFacility number/ID I would like it to be able to show the Facility.Name value. If I place the filed Facility.Name field on my report it is blank.
How can I write a where clause to query the Name of the Facility where the Facility.Code = FDC_Trips.DivertedbyFacility?
Do I use the Select Expert or SQL Expression Fields.
Please advise.Actually you'll use the Links tab in the Database Expert. If CR did it's stupid auto linking thing... delete them. It usually get's it wrong.
Now just link the fk field in FDC_Trips to the pk field in Facility. Once you have that done you'll be able to simply drop Facility.FacilityName directly onto the report.
HTH,
Jason -
Select works with SQL Server but not with Oracle!
Hello
this select works on SQL Server correct, but it don't work on Oracle!
Can someone help me?
Select * from Tabelle, Tabelle as XXX Where Tabelle.ID=XXX.IDTabelle
Thanks
ThomasHi,
These are the things which I have noticed, which wont work in Oracle ..
Table As XXX ?? Are you giving alias name for the table .. The syntax which you have givne doesnt work in Oracle
Regards -
Insert into using a select and dynamic sql
Hi,
I've got hopefully easy question. I have a procedure that updates 3 tables with 3 different update statements. The procedure goes through and updates through ranges I pass in. I am hoping to create another table which will pass in those updates as an insert statement and append the data on to the existing data.
I am thinking of using dynamic sql, but I am sure there is an easy way to do it using PL/SQL as well. I have pasted the procedure below, and what I'm thinking would be a good way to do it. Below I have pasted my procedure and the bottom is the insert statement I want to use. I am faily sure I can do it using dynamic SQL, but I am not familiar with the syntax.
CREATE OR REPLACE PROCEDURE ACTIVATE_PHONE_CARDS (min_login in VARCHAR2, max_login in VARCHAR2, vperc in VARCHAR2) IS
BEGIN
UPDATE service_t SET status = 10100
WHERE poid_id0 in
(SELECT poid_id0 FROM service_t
WHERE poid_type='/service/telephony'
AND login >= min_login AND login <= max_login);
DBMS_OUTPUT.put_line( 'Service Status:' || sql%rowcount);
UPDATE account_t SET status = 10100
WHERE poid_id0 IN
(SELECT account_obj_id0 FROM service_t
WHERE poid_type = '/service/telephony'
AND login >= min_login AND login <= max_login);
DBMS_OUTPUT.put_line( 'Account Status:' || sql%rowcount);
UPDATE account_nameinfo_t SET title=Initcap(vperc)
WHERE obj_id0 IN
(SELECT account_obj_id0 FROM service_t
WHERE poid_type='/service/telephony'
AND login >=min_login AND login <= max_login);
DBMS_OUTPUT.put_line('Job Title:' || sql%rowcount);
INSERT INTO phone_card_activation values which = 'select a.status, s.status, s.login, to_char(d.sysdate,DD-MON-YYYY), ani.title
from account_t a, service_t s, account_nameinfo_t ani, dual d
where service_t.login between service_t.min_login and service_t.max_login
and ani.for_key=a.pri_key
and s.for_key=a.pri_key;'
END;
Thanks for any advice, and have a good weekend.
GeordieCorrect my if I am wrong but aren't these equal?
UPDATE service_t SET status = 10100
WHERE poid_id0 in
(SELECT poid_id0 FROM service_t
WHERE poid_type='/service/telephony'
AND login >= min_login AND login <= max_login);
(update all the records where there id is in the sub-query that meet the WHERE Clause)
AND
UPDATE service_t SET status = 10100
WHERE poid_type='/service/telephony'
AND login >= min_login AND login <= max_login);
(update all the records that meet the WHERE Clause)
This should equate to the same record set, in which case the second update would be quicker without the sub-query. -
Setting current values in Multiple Select List in SQL Query based Report
Hi,
I have a report based on a sql query that contains a multiple select list. Unfortunately I cannot get the multiple select list to display the current values (p_value) correctly. I have created a page item, :p311_current_versions, that is set using a pre-header process and it returns a value with a colon delimited format e.g. '10.1.2.1.0:10.1.2.2.0'. Then this item is used in the sql query to set the current value (p_value) of the apex_item.select_list_from_query function. However when the table is displayed, instead of having two entries, 10.1.2.1.0 and 10.1.2.2.0 selected, it has an extra entry '10.1.2.1.0:10.1.2.2.0' selected.
Here is my code:
select distinct a.product, a.version from (
select distinct
apex_item.display_and_save(2,product)||apex_item.hidden(1,env_product_id) PRODUCT,
APEX_ITEM.SELECT_LIST_FROM_QUERY(3,decode(product, 'HTTP Server' , :p311_current_versions, version), 'SELECT distinct version d, version r FROM ebs_tech_stack where
product ='''||PRODUCT||'''',
decode(PRODUCT, 'HTTP Server' ,'multiple="multiple" style="width:170px"','style="width:170px"'),
'NO') as version
from ebs_environment_tech_stack
where environment_id = :p311_umgebung_id) a order by a.product
If anyone can help me figure out how to set the current values correctly I'd be really grateful!!
Thanks in advance,
JeanJean,
I don't think this is possible using the apex_item package. The select_list_from_query function accepts only a single value for the second parameter.
Scott -
Selecting from a SQL Server 2005 with long column names ( 30 chars)
Hi,
I was able to set up a db link from Oracle 11.2.0.1 to SQL Server 2005 using DG4ODBC.
My problem is that some column names in the Sql Server are longer than 30 chars and trying to select them gives me the ORA-00972: identifier is too long error.
If I omit these columns the select succeeds.
I know I can create a view in the sql server and query it instead of the original table, but I was wondering if there's a way to overcome it with sql.
My select looks like this:
select "good_column_name" from sometable@sqlserver_dblink -- this works
select "good_column_name","very_long_column_name>30 chars" from sometable@sqlserver_dblink -- ORA-00972ThanksI tried creating a view with shorter column names but selecting from the view still returns an error.
create view v_Boards as (select [9650_BoardId] as BoardId, [9651_BoardType] as BoardType, [9652_HardwareVendor] as
HardwareVendor, [9653_BoardVersion] as BoardVersion, [9654_BoardName] as BoardName, [9655_BoardDescription] as BoardDescription,
[9656_SlotNumber] as SlotNumber, [9670_SegmentId] as SegmentId, [MasterID] as MasterID, [9657_BoardHostName] as BoardHostName,
[9658_BoardManagementUsername] as BoardManagementUsername, [9659_BoardManagementPassword] as BoardManagementPassword,
[9660_BoardManagementVirtualAddress] as BoardManagementVirtualAddress, [9661_BoardManagementTelnetLoginPrompt] as
MANAGEMENTTELNETLOGINPROMPT, [9662_BoardManagementTelnetPasswordPrompt] as MANAGEMENTTELNETPASSPROMPT,
[9663_BoardManagementTelnetCommandPrompt] as MANAGEMENTTELNETCOMMANDPROMPT FROM Boards)performing a select * from this view in sqlserver works and show the short column names
this is the error i'm getting for performing a select * from v_boards@sqlserver_dblink
ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
[Microsoft][SQL Native Client][SQL Server]Invalid column name 'BoardManagementTelnetLoginProm'. {42S22,NativeErr = 207}[Microsoft]
[SQL Native Client][SQL Server]Invalid column name 'BoardManagementTelnetPasswordP'. {42S22,NativeErr = 207}[Microsoft][SQL Native
Client][SQL Server]Invalid column name 'BoardManagementTelnetCommandPr'. {42S22,NativeErr = 207}[Microsoft][SQL Native Client][SQL
Server]Statement(s) could not be prepared. {42000,NativeErr = 8180}
ORA-02063: preceding 2 lines from sqlserver_dblinkI also tried replacing the * with specific column names but it fails on the columns that have a long name (it doesn't recognize the short names from the view)
what am I doing wrong?
Edited by: Pyrocks on Dec 22, 2010 3:58 PM -
Select in pl/sql stored proc.
Hi friends,
I am new to oracle development and were trying to write some basic stored procedure,when i try to put a simple stored select statment in between my 'BEGIN' and 'END' clause it never let me do that,it says that 'INTO' clause is expected,I do not want to store andy specific value in any variable i just want a list of all records from that table,Is there any restriction regarding that,can't I do it,am I doing something wrong.?
If any one of u gentalmen can help me,I will be obliged to u .
Thanks a lot.This is somewhat basic.
We always have to have a receptacle for the result set. In SQL*Plus that receptacle is the screen, hence we can dispense with an explicit INTO clause. PL/SQL is a batch process which doesn't write to the screen, so we have to define variables to hold the data.
PL/SQL gives ius options. Wwe can define our SELECT statement as an explicit cursor, in case we don't need to include the INTO clause in our SELECT but we still have to FETCH the cursor INTO a record. Or we can use an implicit cursor, with an INTO clause.
Those are the rules.
You might find it helpful to read the manual. This link will take you to a page that includes some helpful info; one of the links will take you to the online Oracle documentation.
Re: How to attach a java bean in forms6i
Good luck, APC -
Select works in SQL Workshop, but not as an LOV
I want all venues to appear in my LOV
With their affiliated Performing Arts Center, if one exists.
I get the perfect results when I run it in SQL Workshop.
When I try to create the LOV, I'm told it's invalid, because it includes an in-line query and the first FROM clause must not belong in the in-line query.
Not quite sure what it means, but I'm sure I don't know how to fix it...
SELECT
v.VENUE_NAME, p.pac_name d,
v.VENUE_ID r
from pac p, VENUES v
where v.venue_pacid = p.pac_id(+)
thanks
MarionI'm told it's invalid, because it includes an in-line query and the first FROM clause must not belong in the in-line query.Think that's just an example of why a query might be invalid, as this query clearly doesn't have that.
Jari's right, it has to only return 2 columns, so the venue and PAC values need merged somehow, like:
SELECT
v.VENUE_NAME || nvl2(p.pac_name, ' (', null) || p.pac_name || nvl2(p.pac_name, ')', null) d,
v.VENUE_ID r
from pac p, VENUES v
where v.venue_pacid = p.pac_id (+) -
Select from in SQL Developer fails - SQL*Plus works
Hello All,
I've got the HS connection to MySLQ working correctly and most of the requirements I have with respect to the data is working.
However, i"m only able to test my procedures and functions in SQL*PLus. IN SQL Developer 4.0.0.12 there is always a problem and query results are never displayed.
Thanks in advance for any advice.
Sincerely
JSActually Mike,
The white spaces are appended to the end of the resulting string. I've included the NLS setting for bother Oracle adn MySQL as well as my odbc.ini file
select '"'|| "User" ||'"' as Username from "user"@MYODBC5;
Results (there is white spaces added right after the username, as the result shoudl have been "intm","root" as opposed to "intm "
===============================================================================================================
USERNAME
"intm
USERNAME
"root
NLS _SETTINGS ORACLE
==============================================================
Oracle:
======
NAME
VALUE$
NLS_LANGUAGE
AMERICAN
NLS_TERRITORY
AMERICA
NLS_CURRENCY
$
NLS_ISO_CURRENCY
AMERICA
NLS_NUMERIC_CHARACTERS
NLS_CHARACTERSET
AL32UTF8
NLS_CALENDAR
GREGORIAN
NLS_DATE_FORMAT
DD-MON-RR
NLS_DATE_LANGUAGE
AMERICAN
NLS_SORT
BINARY
NLS_TIME_FORMAT
HH.MI.SSXFF AM
NAME
VALUE$
NLS_TIMESTAMP_FORMAT
DD-MON-RR HH.MI.SSXF
F AM
NLS_TIME_TZ_FORMAT
HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT
DD-MON-RR HH.MI.SSXF
F AM TZR
NLS_DUAL_CURRENCY
$
NLS_COMP
BINARY
NLS_LENGTH_SEMANTICS
BYTE
NLS_NCHAR_CONV_EXCP
FALSE
NAME
VALUE$
NLS_NCHAR_CHARACTERSET
AL16UTF16
NLS_RDBMS_VERSION
11.2.0.2.0
NLS _SETTINGS MYSQL
==============================================================
Oracle:
======
NAME :
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
===========================================================ODBC INI
[myodbc5]
Driver = /usr/lib64/libmyodbc5a.so
Description = Connector/ODBC 5.3.4 Driver DSN
SERVER = 127.0.0.1
PORT = 3306
USER = intm
PASSWORD = *********
DATABASE = mysql
OPTION = 0
TRACE = OFF -
Sub selects in a SQL statement
Hi, I have a query with an obsene amount of sub selects,
for example :
SELECT p.ID,
(select something from data where id = p.id) data1,
(select somelse from data2 where id = p.id) data2,
(select someelse from data3 where id = p.id) data3,
(select someelse from data4 where id = p.id) data4,
(select someelse from data5 where id = p.id) data5,
FROM property P
WHERE ..........
this query is taking a long time to process. Is there a more efficient way of doing such a statement?
thanks in advanceGabe:
Since the original poster said "this query is taking a long time to process", I assumed that there was a one-to-one relationship between properties and each of the dataX tables, otherwise, as you pointed out, he would be complaining about ORA-01427: single-row subquery returns more than one row
In my union, I am returning a single column from each of the data tables (plus the id), and a NULL for each of the other columns in the in-line view. The MAX function just gets the single row for each column that actually has a value.
As a test case, I did:
CREATE TABLE properties AS
SELECT rownum id, object_name
FROM all_objects
WHERE rownum < 11;
CREATE TABLE data1 (id NUMBER, descr VARCHAR2(10));
INSERT INTO data1 VALUES(1, 'ONE');
INSERT INTO data1 VALUES(2, 'TWO');
INSERT INTO data1 VALUES(3, 'THREE');
CREATE TABLE data2 (id NUMBER, descr VARCHAR2(10));
INSERT INTO data2 VALUES(4, 'FOUR');
INSERT INTO data2 VALUES(5, 'FIVE');
INSERT INTO data2 VALUES(6, 'SIX');
CREATE TABLE data3 (id NUMBER, descr VARCHAR2(10));
INSERT INTO data3 VALUES(7, 'SEVEN');
INSERT INTO data3 VALUES(8, 'EIGHT');
INSERT INTO data3 VALUES(9, 'NINE');The original version as posted retrieves:
SQL> SELECT p.id, p.object_name,
2 (SELECT descr FROM data1 WHERE id = p.id) data1,
3 (SELECT descr FROM data2 WHERE id = p.id) data2,
4 (SELECT descr FROM data3 WHERE id = p.id) data3
5 FROM properties p
6 ORDER BY p.id;
ID OBJECT_NAME DATA1 DATA2 DATA3
1 TAB$ ONE
2 I_IND1 TWO
3 I_COBJ# THREE
4 USER$ FOUR
5 I_OBJ1 FIVE
6 I_PROXY_ROLE_DATA$_2 SIX
7 BOOTSTRAP$ SEVEN
8 I_ICOL1 EIGHT
9 UNDO$ NINE
10 PROXY_ROLE_DATA$
10 rows selected.
Statistics
0 recursive calls
0 db block gets
93 consistent gets
0 physical reads
0 redo size
1000 bytes sent via SQL*Net to client
655 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
10 rows processedBut, it does a SELECT (hopefully indexed) of data1, data2, and data3 for each row in properties. Minimally, 9 gets per row of properties (index root, index leaf, table row for each of data1, data2, data3) without even getting any data from properties.
My query returns:
SQL> SELECT p.id, p.object_name, a.data1, a.data2, a.data3
2 FROM properties p,
3 (SELECT id, MAX(data1) data1, MAX(data2) data2, MAX(data3) data3
4 FROM (SELECT id, descr data1, TO_CHAR(NULL) data2, TO_CHAR(NULL) data3
5 FROM data1
6 UNION ALL
7 SELECT id, TO_CHAR(NULL), descr, TO_CHAR(NULL)
8 FROM data2
9 UNION ALL
10 SELECT id, TO_CHAR(NULL), TO_CHAR(NULL), descr
11 FROM data3)
12 GROUP BY id) a
13 WHERE p.id = a.id(+)
14 ORDER BY p.id;
ID OBJECT_NAME DATA1 DATA2 DATA3
1 TAB$ ONE
2 I_IND1 TWO
3 I_COBJ# THREE
4 USER$ FOUR
5 I_OBJ1 FIVE
6 I_PROXY_ROLE_DATA$_2 SIX
7 BOOTSTRAP$ SEVEN
8 I_ICOL1 EIGHT
9 UNDO$ NINE
10 PROXY_ROLE_DATA$
10 rows selected.
Statistics
0 recursive calls
0 db block gets
12 consistent gets
0 physical reads
0 redo size
1000 bytes sent via SQL*Net to client
655 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
10 rows processedThe same result, but 1/8 of the gets. an outer join is also possible:
SQL> SELECT p.id, p.object_name, d1.descr data1, d2.descr data2, d3.descr data3
2 FROM properties p, data1 d1, data2 d2, data3 d3
3 WHERE p.id = d1.id(+) AND
4 p.id = d2.id(+) AND
5 p.id = d3.id(+)
6 ORDER BY p.id;
ID OBJECT_NAME DATA1 DATA2 DATA3
1 TAB$ ONE
2 I_IND1 TWO
3 I_COBJ# THREE
4 USER$ FOUR
5 I_OBJ1 FIVE
6 I_PROXY_ROLE_DATA$_2 SIX
7 BOOTSTRAP$ SEVEN
8 I_ICOL1 EIGHT
9 UNDO$ NINE
10 PROXY_ROLE_DATA$
10 rows selected.
Statistics
0 recursive calls
0 db block gets
12 consistent gets
0 physical reads
0 redo size
1000 bytes sent via SQL*Net to client
655 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
10 rows processedSo, the same number of gets, and it saves one sort. But if the tables are large, multiple outer joins may not be as efficient as one outer join to the union all query.
HTH
John -
Using Multi Select List in SQL Query
Hi all,
I am trying to using a Multi Select list for filtering of a report. I have :P2_RISK_SEVERITY which has has the possibility of values Very Low:Low:Medium:High:Very High. How do I use this Multi Select in the where section of a SQL query?
I need to say something along the lines of:
Select RISK_SEVERITY from TBL_RMD_RISKS where RISK_SEVERITY = (one of the options selected in the multi select)
Thanks for the help.Hi there,
The above suggestion will work perfectly as long as the table you're querying is relatively small, but keep in mind that applying the INSTR to the left side of the WHERE clause will always result in a full table scan. This means that if your table is large and RISK_SEVERITY is indexed, the index will never be used. Here is another approach (credit to AskTom) that converts your colon-delimited string of selected values to a list that can be used in an "IN(...)" clause, which will use an index on RISK_SEVERITY as long as the optimizer otherwise deems it appropriate:
-- creates a type to hold a list of varchars
CREATE OR REPLACE TYPE vc2_list_type as table of varchar2(4000);
-- converts a colon-delimited string of values to a list of varchars
CREATE OR REPLACE FUNCTION vc2_list(p_string in varchar2)
return vc2_list_type is
l_string long default p_string || ':';
l_data vc2_list_type := vc2_list_type();
n pls_integer;
begin
loop
exit when l_string is null;
n := instr(l_string, ':');
l_data.extend;
l_data(l_data.count) := ltrim(rtrim(substr(l_string, 1, n - 1)));
l_string := substr(l_string, n + 1);
end loop;
return l_data;
end vc2_list;
-- your WHERE clause
where risk_severity in(
select *
from the(select cast(vc2_list(:P2_RISK_SEVERITY) as vc2_list_type)
from dual))
...Hope this helps,
John -
How to processing the results from the select statement in SQL query?
Hi
This might be too simple, but my knowledge of the SQL is very limited...
I have table where I do have details from calls (Lync QoE).
I can take all calls from the table, but I would like to count the concurrent calls on the table. This is how I got it work on the Excel to work (but I would like to do that on the SQL statement to get it more dynamic use):
Table have these line and this is what I get out from the Select):
[callid],[start],[end]
1ABC,1.1.2014 01:00:15, 1.1.2014 01:01:00
5DEF,1.1.2014 01:00:45, 1.1.2014 01:05:00
FDE2,1.1.2014 01:03:15, 1.1.2014 01:04:00
KDJ8,1.1.2014 01:04:15, 1.1.2014 01:06:00
FDJ8,2.1.2014 01:04:15, 2.1.2014 01:06:00
KDSE,3.1.2014 01:04:15, 3.1.2014 01:06:00
The information I would like to get, is what is the maximum amount of the concurrent calls per day.
On the excel I basically count line by line how many concurrent calls each line have had, and then pickup the highest one. On above example the calls 5DEF, FDE2 and FDE2 have been active at the same time which gives 3 for the first day.
The table is ordered by the start. So let say the code is on the third line (FDE2). I need to count calls from before which end time is after the start time (of FDE2), but also I need to count calls after (FDE2) which are started before the current
call has ended.
PetriUnfortunately your post is off topic as it's not specific to SQL Server Samples and Community Projects.
This is a standard response I’ve written in advance to help the many people who post their question in this forum in error, but please don’t ignore it. The links I provide below will help you determine the right forum to ask your question in.
For technical issues with Microsoft products that you would run into as an end user, please visit the Microsoft Answers forum ( http://answers.microsoft.com ) which has sections for Windows, Hotmail,
Office, IE, and other products.
For Technical issues with Microsoft products that you might have as an IT professional (like technical installation issues, or other IT issues), please head to the TechNet Discussion forums at http://social.technet.microsoft.com/forums/en-us, and
search for your product name.
For issues with products you might have as a Developer (like how to talk to APIs, what version of software do what, or other developer issues), please head to the MSDN discussion forums at http://social.msdn.microsoft.com/forums/en-us, and
search for your product or issue.
If you’re asking a question particularly about one of the Microsoft Dynamics products, a great place to start is here: http://community.dynamics.com/
If you think your issue is related to SQL Server Samples and Community Projects and I've flagged it as Off-topic, I apologise. Please repost your question and include as much detail as possible about your problem so that someone can assist you further.
If you really have no idea where to post your question please visit the Where is the forum for…? forum http://social.msdn.microsoft.com/forums/en-us/whatforum/
When you see answers and helpful posts, please click Vote As Helpful,
Propose As Answer, and/or Mark As Answer
Jeff Wharton
MSysDev (C.Sturt), MDbDsgnMgt (C.Sturt), MCT, MCPD, MCSD, MCSA, MCITP, MCDBA
Blog: Mr. Wharty's Ramblings
Twitter: @Mr_Wharty
MC ID:
Microsoft Transcript -
SEQUENCE Select within an SQL Query with an ORDER BY statement
Does anyone know why you cannot use an ORDER BY statement within an SQL query when also selecting from a SEQUENCE? My query was selecting production data as a result of a filtered search. I want to take the results of the filtered search and create a transaction. I have a sequence for generating transaction numbers where I select NEXTVAL. Since I could possibly obtain multiple, yet distinct, rows based upon my search criteria, I wanted to use an ORDER BY statement to simplify and order the resulting row(s).
I was able to get the SQL select with SEQUENCE.NEXTVAL to work without the ORDER BY, so I know that my SQL is correct. Thanks in-advance.Okay,
I understand. You want the sequence assigned first and the you want to ORDER BY. You
can do this using pipelined functions. See here:
CREATE OR REPLACE TYPE emp_rec_seq AS OBJECT (
seq NUMBER,
ename VARCHAR2 (20),
job VARCHAR2 (20),
sal NUMBER
CREATE OR REPLACE TYPE emp_tab_seq AS TABLE OF emp_rec_seq;
CREATE OR REPLACE FUNCTION get_emp_with_sequence
RETURN emp_tab_seq PIPELINED
IS
my_record emp_rec_seq := emp_rec_seq (NULL, NULL, NULL, NULL);
BEGIN
FOR c IN (SELECT dummy.NEXTVAL seq, ename, job, sal
FROM emp)
LOOP
my_record.seq := c.seq;
my_record.ename := c.ename;
my_record.job := c.job;
my_record.sal := c.sal;
PIPE ROW (my_record);
END LOOP;
RETURN;
END get_emp_with_sequence;after that, you can do a select like this:
SELECT seq, ename, job, sal
FROM TABLE (get_emp_with_sequence)
order by enamewhich will get you this:
SEQ ENAME JOB SAL
1053 BLAKE MANAGER 2850
1054 CLARK MANAGER 2450
1057 FORD ANALYST 3000
1062 JAMES CLERK 950
1055 JONES MANAGER 2975
1052 KING MANAGER 20000
1060 MARTIN SALESMAN 1250
1063 MILLER CLERK 1300
1064 DKUBICEK MANAGER 12000
1056 SCOTT ANALYST 3000
1058 SMITH CLERK 800
1061 TURNER SALESMAN 1500
1059 WARD SALESMAN 1250Denes Kubicek
http://deneskubicek.blogspot.com/
http://htmldb.oracle.com/pls/otn/f?p=31517:1
------------------------------------------------------------------- -
Select in PL/SQL tables ?
Hi,
I have create PL/SQL Table , i want to know how can i remove the redundancy of data as
in SQL query when i used UNION ALL or DISTINCT Operators.
The second Question is How can show(Retrieve query) only one element in SQL
SUCH AS
SELECT ID from PL/SQL Table Name;
Create or replace PACKAGE Test1 IS
type REC_DB is RECORD
(id number(9), name varchar2(50));
type TB_DATA IS table of REC_DB;
function get_coll return TB_DATA pipelined;
temp_TB_DATA TB_DATA := TB_DATA();
type CV_TEST is REF CURSOR return REC_DB ;
end;
Package created.
Create or replace PACKAGE body TEST1 IS
function get_coll return TB_DATA pipelined
is
begin
for i in 1..temp_TB_DATA.count loop
pipe row(temp_TB_DATA (i));
end loop;
return;
end;
end;
Package body created.
declare
temp_cv TEST1.CV_TEST ;
rc TEST1.REC_DB ;
a number(9);
begin
TEST1.temp_TB_DATA.delete;
TEST1.temp_TB_DATA.extend;
TEST1.temp_TB_DATA(1).id:=1;
TEST1.temp_TB_DATA(1).name:='SITI';
TEST1.temp_TB_DATA(1).id:=2;
TEST1.temp_TB_DATA(1).name:='OMAR';
TEST1.temp_TB_DATA(1).id:=3;
TEST1.temp_TB_DATA(1).name:='ALI';
TEST1.temp_TB_DATA(1).id:=4;
TEST1.temp_TB_DATA(1).name:='DAID';
TEST1.temp_TB_DATA(1).id:=1;
TEST1.temp_TB_DATA(1).name:='SITI';
TEST1.temp_TB_DATA(1).id:=2;
TEST1.temp_TB_DATA(1).name:='OMAR';
-- erroring out
open temp_cv for select * from table(TEST1.get_coll);
fetch temp_cv into rc;
dbms_output.put_line('Deptno is ' || rc.id);
dbms_output.put_line('ename is ' || rc.name);
end;
regardsAyham wrote:
I have create PL/SQL Table , i want to know how can i remove the redundancy of data as
in SQL query when i used UNION ALL or DISTINCT Operators.Repeat. There is no such thing as a PL/SQL "table". There is no such thing as a PL/SQL "table". There is no such thing as a PL/SQL "table".
The data structure is called an array. A table in Oracle has a very specific meaning. It is a hash or index table. Can be partitioned. Clustered. Indexed. Etc.
A PL/SQL array is NOTHING at all like a table.
The second Question is How can show(Retrieve query) only one element in SQL
SUCH AS
SELECT ID from PL/SQL Table Name;And this is almost always WRONG. As you are sending (a potentially large) array that resides in PL/SQL memory as a bind variable to the SQL engine, in order for the array's contents to be processed. Why?
Why not simply use a (proper SQL) table and not array? A table that can be indexed. That was made for running SQL against? That can take billions of rows without exhausting server memory.
If you are using SQL against a PL/SQL array, you are basically saying "+I have made the wrong choice for processing this data+". Yes, there are exceptions to this. But exceptions are just that - exceptions.
So why are you using a PL/SQL array? Why do you need to use SQL against it and duplicate the array's contents as bind values? Why does SET operations in PL/SQL not suffice? -
Inline select statement and SQL optimizatino
Hi everyone,
I am trying to optimze a script but can't get the fulle explainplan in PL/SQL.
The problem is that the select statements in de column defenition is not explained. below are the 2 scripts I want to compare:
SQL1:
Select
z.title
, (select name from members where id =z.id) as name
, z.id
from job z
SQL2
Select
z.title
, d.name
, z.id
from job z
left outer join members d on z.id=d.id
My question is: what is the effect on performance and cost of the 'inline select' statement of name in SQL1
hope to hear form you soon
Harm
Edited by: HALI on 25-nov-2010 1:14In respons to your question below is the output:
I altered the used names, tablenames etc. according to our privacy pollacy.
A far as I can see the inline statement is not traced.
The query with ansi-join:
xplain plan for
select
id as Interne
, mv.ie_id as Act
, 'H_W' as Rl
from testing i
left outer join resutino m on i.hand=m.id
left outer join vert mv on m.voor || case when m.voeg is not null then ' '|| m.voeg end ||' '||m.naam = mv.source and mv.field = 'employee'
explain plan succeeded.
select * from table(dbms_xplan.display)
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 684 | 47880 | 19 |
| 1 | HASH JOIN OUTER | | 684 | 47880 | 19 |
| 2 | HASH JOIN OUTER | | 684 | 22572 | 15 |
| 3 | TABLE ACCESS FULL | testing | 684 | 5472 | 7 |
| 4 | TABLE ACCESS FULL | resutino | 308 | 7700 | 7 |
| 5 | TABLE ACCESS FULL | VERT | 166 | 6142 | 3 |
Note: cpu costing is off, 'PLAN_TABLE' is old version
13 rows selected
The inline select query:
xplain plan for
SELECT
case when (select ie_id from vert xov where xov.field = 'field' and source in
(select m.voor || case when m.voeg is not null then ' '|| m.voegend ||' '||m.naam from resultino m where i.hand= m.id)) is not null then
'X'||(select ie_id from vert xov where xov.field = 'field' and source in
(select m.voor || case when m.voeg is not null then ' '|| m.voegend ||' '||m.naam from resultino m where i.hand= m.id))
else 'X' || (select ie_id from vert xov where xov.source = 'none' and xov.veld = 'employee')
end as Act,
'ADM' as Rol,
i.id as Interne
FROM testing i
explain plan succeeded.
select * from table(dbms_xplan.display)
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 684 | 5472 | 7 |
| 1 | TABLE ACCESS FULL | testing | 684 | 5472 | 7 |
Note: cpu costing is off, 'PLAN_TABLE' is old version
9 rows selected
Maybe you are looking for
-
How to set multiple Last page placement in a page set
Problem statement Form with the 4 subforms named A to D. A turns B on or off, D is only visible when printing. When viewing the form interactively I need the following order (number in brackets indicates columns): When printing the form I need the fo
-
Flex tree control expanditem dynamically..?
Hi All., I have using tree control using to display. when i pass the data with folder id dynamically to expanding particular child node of tree. How to extarct tree with dynamic...? Below sample coding..... <mx:tree id="folderTree" />
-
Sometimes users open very large spools displaying thousands of pages. We want to restrict maximum number of pages that can be displayed in SP01 , e.g. up to 40 pages. We do not want to restrict size of spool. Users should be able to create spools of
-
1st Meet-the-expert session is now open for registration
Hello, SAP's CAF PM team will start a session series (so called 'Meet-the-expert' sessions) to bring closer the CAF topic to the SDN community. The first session is now arranged and open for registration (<a href="https://sap.webex.com/sap/j.php?ED=8
-
Apple tv hook up with ebay converter
Hello Apple fans Will this product from ebay solve my problems? I need to connect my apple tv sith my tv (which doesn't have a hdmi input) trough my revices. http://www.ebay.co.uk/itm/HDMI-5-RCA-Component-AV-Converter-PS3-Bluray-HD-/33066 5477926?pt=