Concatenate the select result of a statement under...
OK, here's my problem. I have 2 tables, a reference to the other. Several rows of table B belong to datas from the table A and I would do a select where I can "Concatenate" the content of the data in table B in one of my select line.So, here is what I did:
select distinct d.code,
c.libe "Nom",
d.ddeb "Date de dépot",
d.nume "Numéro de demande",
(select p.libe from demande p where p.code=d.nume and p.natu='T' and tri=1
)
||' '
||
(select p.libe from demande p where p.code=d.nume and p.natu='T' and tri=2
)
||' '
||
(select p.libe from demande p where p.code=d.nume and p.natu='T' and tri=3
)
||' '
||
(select p.libe from demande p where p.code=d.nume and p.natu='T' and tri=4
)
||' '
||
(select p.libe from demande p where p.code=d.nume and p.natu='T' and tri=5
) "type",
(select p.libe from demande p where p.code=d.nume and p.natu='C' and tri=1
)
||' '
||
(select p.libe from demande p where p.code=d.nume and p.natu='C' and tri=2
)
||' '
||
(select p.libe from demande p where p.code=d.nume and p.natu='C' and tri=3
)
||' '
||
(select p.libe from demande p where p.code=d.nume and p.natu='C' and tri=4
)
||' '
||
(select p.libe from demande p where p.code=d.nume and p.natu='C' and tri=5
) "Commune"
from demandeur d,
demande t,
client c
where t.code=d.nume
and c.code =d.code
and c.role ='1'
and t.natu ='T'
and dfin is null
and ddeb <'30/09/2008'
and clot is null
and d.nume in
(select u.code from demande u where u.libe in ('F1','F 1bis','F2','F3')
)
order by d.ddeb asc ;
The problem is that this method will display only the first five rows of the table B (request). In table B, there could be between rows 1 and 14 for "Common" and up to 10 lines for 'Type '.Would there be any cleaner method or smarter to cela?
THX
Create a PL/SQL function like this:
NOT TESTED
create or replace function getTypes(p_nume in number) return varchar2 is
retval varchar2(32000);
begin
for r in (select libe from demande where code=p_nume and natu='T' order by tri) loop
retval := retvale||r.libe||' ';
end loop;
return retval;
end;
/
select distinct d.code,
c.libe "Nom",
d.ddeb "Date de dépot",
d.nume "Numéro de demande",
getTypes(d.nume) type
from demandeur d,
demande t,
client c
where t.code=d.nume
and c.code =d.code
and c.role ='1'
and t.natu ='T'
and dfin is null
and ddeb <'
and clot is null
and d.nume in
(select u.code from demande u where u.libe in ('F1','F 1bis','F2','F3')
)
order by d.ddeb asc ;
Max
Tags: Database
Similar Questions
-
don't forget the select result of a statement to be used several times in the procedure
Hi all
I'm sorry for this kind of question, I'm not newbie, but still need your help.
My need is remember the select result of a statement to be used several times in the procedure.
My first guess is to use a temporary table, but I think there's better decisions.
For example, I should make a heavy request
Select the code from table_function (param1)
Then, this query is used to insert a list of the id in table1, delete table2 and update in table 3.
Help me please do not use if possible temporary tables.
If there is more than one column, you need to create an object type at the database level. Create a collection of this type of object in the procedure.
Example:
CREATE OR REPLACE TYPE "OBJ1" as OBJECT( column1 varchar2(256 CHAR), column2 varchar2(35 CHAR) ); CREATE OR REPLACE TYPE "nt_obj1" as table of OBJ1; -- this could be done at procedure level as well DECLARE t_employee_ids nt_obj1; BEGIN SELECT OBJ1(column1,column2) BULK COLLECT INTO t_employee_ids FROM table1 WHERE column3 = NNN ............. .....
-
Concatenate the previous results
Hi all
I have an analysis that returns the following values:
Code Description 1 N/A 2 3 TEST In the end, I would add a third column would be:
Code Description ConcatenatedDescription 1 N/A N/A, TEST 2 N/A, TEST 3 TEST N/A, TEST The goal is to concatenate all the distinct values of the Description in ConcatenatedDescription and repeat along the rows. Is anyway to do the analysis?
Best regards
André
Try this:
EVALUATE_AGGR ('LISTAGG (%1, %2) within THE GROUP (ORDER BY DESC %3)', Description, ",", Description)
Concerning
-
Several results of the Select statement horizontally
Hello
DB Version: Oracle 11.1.2.1.0
OS: OEL5
I try to print the results of several SELECT horizontally using SQL statements, but not able to reach my goal.
Multiple SQLs:
SELECT 'DB Version', version db_version FROM v$instance UNION ALL select 'Oracle Client', length(addr)*4 || '-bits' word_length from v$process where ROWNUM =1 UNION ALL select 'Database Edition', trim(substr(banner,20,19)) from v$version where rownum<2 UNION ALL SELECT 'Single Instance or RAC', CASE COUNT(1) WHEN 1 THEN 'Single Instance' ELSE 'RAC' END is_single_instance FROM gv$instance UNION ALL SELECT 'No of CPUS', to_char(value) FROM v$osstat WHERE stat_name='NUM_CPUS' UNION ALL SELECT 'No of CPU Cores', to_char(value) FROM v$osstat WHERE stat_name='NUM_CPU_CORES' UNION ALL SELECT 'No of CPU Sockets', to_char(value) FROM v$osstat WHERE stat_name='NUM_CPU_SOCKETS' UNION ALL SELECT 'Physical Memory (GB)', to_char(ROUND((value/1024/1024/1024),3)) FROM v$osstat WHERE stat_name='PHYSICAL_MEMORY_BYTES' /
Result:
'DBVERSION' DB_VERSION ---------------------- ---------------------------------------------------------------------------- DB Version 11.2.0.1.0 Oracle Client 64-bits Database Edition Enterprise Edition Single Instance or RAC Single Instance No of CPUS 4 No of CPU Cores 2 No of CPU Sockets 1 Physical Memory (GB) 3.864 8 rows selected.
Expected result:
DB VERSION ORACLE CLIENT DATABASE EDITION SINGLE INSTANCE OR RAC NO OF CPUS NO OF CPU CORES NO OF CPU SOCKETS PHYSICAL MEMORY (GB) ----------- --------------- ------------------------ -------------------------- ----------- ---------------- ------------------ --------------------- 11.2.0.1.0 64-bits Enterprise Edition Single Instance 4 2 1 3.84
Any help would be greatly appreciated.
Val
SELECT "DB Version."
"Oracle Client."
"Database Edition."
"Single instance or RAC.
"None of the processors."
"No CPU Cores.
"No CPU Sockets."
"Physical memory (GB).
OF (choose the version "DB Version" of v$ instance where rownum)<>
(choose the length (addr) * 4 | bits "Oracle Client" from v$ process where ROWNUM = 1).
(select trim (substr (banner, 20: 19)) "Database Edition" version $ v where rownum)<>
(select CASE COUNT (1) WHEN 1 THEN 'Single Instance' ELSE 'RAC' END 'Single Instance or RAC' SGS $ instance).
(SELECT to_char (value) 'Number of processors' v$ stat_name WHERE osstat = 'NUM_CPUS'),
(SELECT to_char (value) "Number of CPU cores" v $ stat_name WHERE osstat = 'NUM_CPU_CORES'),
(SELECT to_char (value) 'number of CPU Sockets"v$ stat_name WHERE osstat = 'NUM_CPU_SOCKETS'),
(SELECT to_char (ROUND ((value/1024/1024/1024), 3)) 'physical memory (GB)' v $ stat_name WHERE osstat = "PHYSICAL_MEMORY_BYTES")
/
DB Version Oracle customer Database Edition Single Instance No. No. processors CPU Cores No. CPU Sockets physical memory (GB)
----------------- --------------- ------------------- --------------- ---------- --------------- ----------------- --------------------
11.2.0.3.0 64-bit Enterprise Edition Single Instance 4 4 and 1 7.991SQL >
SY.
-
Insert the select statement result in CLOB
Hi, I would like to insert the result of a statement select into a CLOB with a trigger.
Whevner a number is registered my research to trigger how often the number is used in several objects and now my problem I also would like to know the record ID where the number is used.
SELECT 'ITEXT '.
OF 'CHECK_INR '.
WHERE 'USE' > 1
This select records of results 2 How can I insert the result into a CLOB with my trigger?
Thanks in advanceSteven,
It's really a question better suited for another forum because it is not really associated with ApEx. Also, something tells me that you really want to do an UPDATE not an insert. However, here's a quick example...
DECLARE l_orders VARCHAR2(4000); BEGIN FOR x IN ( SELECT * FROM my_orders_table ) LOOP l_orders := l_orders || ', ' || x.order_data_column; END LOOP; l_orders := l_trim(l_orders, ', '); UPDATE some_table SET some_column = l_orders WHERE id = some_id; END;
That's the key. Use VARCHAR2 unless you need CLOB.
Kind regards
Danhttp://danielmcghan.us
http://sourceforge.NET/projects/tapigen -
Pivot will not get result in the select statement
This is the version of oracle 11g R2 on windows details 7 OS
CREATE TABLE OTBOOKINGDETAILS
(EMPNO VARCHAR2 (10 BYTE),
DATE OF OTBOOKEDDATE,
NUMBER (5.0) DAY OF THE WEEK.
DAYCEILINGHRS VARCHAR2 (10 BYTE));
Here is the data
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 MARCH 2013', 1,' 09:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 APRIL 2013', 2' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 MAY 2013', 3,' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 JUNE 2013', 4' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 JULY 2013', 5,' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 AUGUST 2013', 6,' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 SEPTEMBER 2013', 7,' 00:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 MARCH 2013', 1,' 09:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 APRIL 2013', 2' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 MAY 2013', 3,' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 JUNE 2013', 4,' 02:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 JULY 2013', 5,' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 AUGUST 2013', 6,' 04:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 SEPTEMBER 2013', 7' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 OCTOBER 2013', 1,' 00:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 NOVEMBER 2013', 2' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 DECEMBER 2013', 3,' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 13 MARCH 2013', 4,' 04:45 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 14 MARCH 2013', 5,' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 15 MARCH 2013', 6,' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 16 MARCH 2013', 7' 01:00 ');
Here, I want to Dayceiling hours below the output using pivot
EMPNO OTBOOKEDDATE DAY1_HRS DAY2_HRS DAY3_HRS DAY4_HRS DAY5_HRS DAY6_HRS DAY7_HRS
101 03/03/2013 09:00 01:00 01:00 01:00 01:00 01:00 00:00
102 03/03/2013 09:00 01:00 01:00 02:00 01:00 04:00 01:00
101 03/10/2013 00:00 01:00 01:00 04:45 01:00 01:00 01:00ChakravarthyDBA wrote:
I need to include the pivot query in the select statementCan' are you use PIVOT here since you do not know from the start what values OTBOOKEDDATE. So use:
select empno, otbookeddate - weekday + 1 otbookeddate, max( case weekday when 1 then dayceilinghrs end ) day1_hrs, max( case weekday when 2 then dayceilinghrs end ) day2_hrs, max( case weekday when 3 then dayceilinghrs end ) day3_hrs, max( case weekday when 4 then dayceilinghrs end ) day4_hrs, max( case weekday when 5 then dayceilinghrs end ) day5_hrs, max( case weekday when 6 then dayceilinghrs end ) day6_hrs, max( case weekday when 7 then dayceilinghrs end ) day7_hrs from otbookingdetails group by empno, otbookeddate - weekday + 1 order by otbookeddate, empno / EMPNO OTBOOKEDDA DAY1_HRS DAY2_HRS DAY3_HRS DAY4_HRS DAY5_HRS DAY6_HRS DAY7_HRS ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 101 03-03-2013 09:00 01:00 01:00 01:00 01:00 01:00 00:00 102 03-03-2013 09:00 01:00 01:00 02:00 01:00 04:00 01:00 101 10-03-2013 00:00 01:00 01:00 04:45 01:00 01:00 01:00 SQL>
SY.
-
In the Select statement using substring comparison
Hello
Based on the requirement of the enterprise, I m trying to get geography_element4 to the hz_geographies table that corresponds to the value of the p_city parameter.
Here, I take p_city from the 4th character value to 8 characters.
For under query, I m not getting the correct result. The statement is true? GE.geography_element4 as substr(:p_city,4,8);
SELECT UPPER (ge.geography_element4)
OF apps.hz_geographies ge
WHERE ge.geography_type = "zip_code".
AND ge.geography_name = SUBSTR(:postal_code,1,5)
AND ge.created_by_module = 'EBTAX_CONTENT_UPLOAD. '
AND ge.country_code = 'en '.
AND ge.geography_element4 like substr(:p_city,4,8);
Thank you.
ef2019c7-080c-4475-9cf4-2cf1b1057a41 wrote:
Can I use something like '% substr(:p_city,4,5) % '.
Yes, you should, but using the correct syntax. Do you understand how AS works? It involves wildcards are used in similar Configuration. Otherwise, it's same as equals. Assume that p_city is "FT LAUDERDALE". Then substr(:p_city,4,5) is 'LAUDE '. Then ge.geography_element4 AND as substr(:p_city,4,5) will compare "FT. LAUDERDALE" "LAUDE", of course, without a game. When wrap you it with jokers '% "| substr(:p_city,4,5) | '%' AS get ge.geography_element4 that contains "LAUDE" and "FT LAUDERDALE" will be a game.
SY.
-
uniol all in the select statement
Hi I have a situation where I have to return the value based on the if statement, is it possible to put union all in the select statement
My use case is
IN the column State
If column01 > 0 to condtion 't'
IF column02 > 0 that the condition of 'Y '.
Condition IF COLUMN03 > 0 THAN 'w '.
If COLUMN04 > 0 that the condition of "Z".
Select 't'
TableName
where column01 > 0
Union of all the
Select "y".
TableName
where column02 > 0
Union of all the
Select 'W '.
TABLENAME
WHERE COLUMN03 > 0
I have what it takes to show value as it
EmpName, condition, empno
Jerry, T, 0158754585
TOM, Y, 0054789568
Am in oracle database 11 g 2
Yes you can put all THE UNION here
Select empname, 't' State, empno from tablename where column01 > 0
Union of all the
Select empname, 't' State, empno from tablename where column02 > 0
Union of all the
Select empname, condition of "W", empno FROM tablename WHERE COLUMN03 > 0
Union of all the
Select empname, condition of "Z", empno FROM tablename WHERE COLUMN04 > 0
and if you are looking for how to remove duplicates because your line might have satisfied all the conditions and my happen 4 times in your result set, you just need to give them an order and filter it.
For example, you want this
If column01 > 0 to condtion 't'
ELSE IF column02 > 0 that the condition of 'Y '.
Another condition of THAN > 0 IF COLUMN03 'w '.
otherwise if COLUMN04 > 0 that the condition of "Z".
Select empname, condition, empno, in
(
Select a.*, row_number() over (partition by empno arrested by myorder) rn
Of
(
Select empname, 't' State, empno, 1 myorder tablename where column01 > 0
Union of all the
Select empname, 't' State, empno, 2 myorder tablename where column02 > 0
Union of all the
Select empname, condition of "W", empno 3 myorder FROM tablename WHERE COLUMN03 > 0
Union of all the
Select empname, empno, condition of 'Z', 4 myorder FROM tablename WHERE COLUMN04 > 0
) a
) where rn = 1
-
passing multiple values from the query in the select statement of the procedure
I am collecting IDS to select education agreement from the date of rental values and then I would pass the result of the query in the statement select to get the result.
data type for the contract id is of type varchar and date of rental there is more than one id to contract for most of the time. Help, please. Thank you
CREATE OR REPLACE PROCEDURE abstract_menu (p_letting IN VARCHAR2, p_results OUT SYS_REFCURSOR) IS v_contractId VARCHAR2 (40); SELECT lcontid INTO v_contractId FROM letprop WHERE datestat IS NOT NULL AND letting = p_letting AND letstat <> 'R'; BEGIN OPEN p_results FOR SELECT DISTINCT SUBSTR (l.letting, 3, 2) || '-' || SUBSTR (l.letting, 5, 2) || '-' || SUBSTR (l.letting, 1, 2) lettingdate, l.lcontid contractid, SUBSTR (q.cprojnum, 1, 10) projectnumber, DECODE (TRIM (MIN (j.route)), NULL, 'N/A', TRIM (MIN (j.route))) routenumber, L.DATESTAT statusdate, L.LETSTAT lettingstatus, (q.cdescr) jobdescription, INITCAP (q.clocat1 || q.clocat2) LOCATION FROM vendor v, vendaddr r, letprop l, planhold p, proposal q, project j, propproj k, bidlet bd WHERE v.vendor = r.vendor AND k.contid = q.contid AND k.pcn = j.pcn AND l.lcontid = k.contid AND p.vendor = v.vendor AND l.letting = p.letting AND l.lcontid IN v_contactid "**************This is where I would like to pass the contract id from the above select statement***********'" AND l.CALL = p.CALL AND r.addrnum = p.billto AND bd.letting = l.letting GROUP BY q.cdescr, q.clocat1, q.clocat2, bd.letting, l.letting, l.lcontid, q.cprojnum, L.LETSTAT, L.DATESTAT ORDER BY lettingdate; end;
user9196150 wrote:
AND l.lcontid IN v_contactid ' * this is where I would like to pass the id of the select statement above contract * ""»CREATE OR REPLACE PROCEDURE abstract_menu (p_letting IN VARCHAR2, p_results OUT SYS_REFCURSOR) IS BEGIN OPEN p_results FOR SELECT DISTINCT SUBSTR (l.letting, 3, 2) || '-' || SUBSTR (l.letting, 5, 2) || '-' || SUBSTR (l.letting, 1, 2) lettingdate, l.lcontid contractid, SUBSTR (q.cprojnum, 1, 10) projectnumber, DECODE (TRIM (MIN (j.route)), NULL, 'N/A', TRIM (MIN (j.route))) routenumber, L.DATESTAT statusdate, L.LETSTAT lettingstatus, (q.cdescr) jobdescription, INITCAP (q.clocat1 || q.clocat2) LOCATION FROM vendor v, vendaddr r, letprop l, planhold p, proposal q, project j, propproj k, bidlet bd WHERE v.vendor = r.vendor AND k.contid = q.contid AND k.pcn = j.pcn AND l.lcontid = k.contid AND p.vendor = v.vendor AND l.letting = p.letting AND l.lcontid IN ( SELECT ll.lcontid FROM letprop ll WHERE ll.datestat IS NOT NULL AND ll.letting = p_letting AND ll.letstat 'R' ) AND l.CALL = p.CALL AND r.addrnum = p.billto AND bd.letting = l.letting GROUP BY q.cdescr, q.clocat1, q.clocat2, bd.letting, l.letting, l.lcontid, q.cprojnum, L.LETSTAT, L.DATESTAT ORDER BY lettingdate; end; /
SY.
-
Not finding the correct syntax for the select statement
Hello
The following statement works very well and gives the expected results:
As an academic exercise, I wanted to rewrite the above statement without using the WITH clause, I tried this (amongst dozens of other tests - I hit a mental block and cannot understand):prompt prompt Using WITH t prompt with t as ( select a.proj_id, a.proj_start, a.proj_end, case when ( select min(a.proj_start) from v b where (a.proj_start = b.proj_end) and (a.proj_id != b.proj_id) ) is not null then 0 else 1 end as flag from v a order by a.proj_start ) select proj_id, proj_start, proj_end, flag, -- -- the following select statement is what I am having a hard time -- "duplicating" without using the WITH clause -- ( select sum(t2.flag) from t t2 where t2.proj_end <= t.proj_end ) s from t;
Thanks for the help, much appreciated.prompt prompt without with prompt select c.proj_id, c.proj_start, c.proj_end, c.flag, -- -- This is what I've tried as the equivalent statement but, it is -- syntactically incorrect. What's the correct syntax for what this -- statement is intended ? -- ( select sum(t2.flag) from c t2 where t2.proj_end <= c.proj_end ) as proj_grp from ( select a.proj_id, a.proj_start, a.proj_end, case when ( select min(a.proj_start) from v b where (a.proj_start = b.proj_end) and (a.proj_id != b.proj_id) ) is not null then 0 else 1 end as flag from v a order by a.proj_start ) c;
John.
PS: The DDL for table v used by the above statements is:
drop table v; create table v ( proj_id number, proj_start date, proj_end date ); insert into v values ( 1, to_date('01-JAN-2005', 'dd-mon-yyyy'), to_date('02-JAN-2005', 'dd-mon-yyyy')); insert into v values ( 2, to_date('02-JAN-2005', 'dd-mon-yyyy'), to_date('03-JAN-2005', 'dd-mon-yyyy')); insert into v values ( 3, to_date('03-JAN-2005', 'dd-mon-yyyy'), to_date('04-JAN-2005', 'dd-mon-yyyy')); insert into v values ( 4, to_date('04-JAN-2005', 'dd-mon-yyyy'), to_date('05-JAN-2005', 'dd-mon-yyyy')); insert into v values ( 5, to_date('06-JAN-2005', 'dd-mon-yyyy'), to_date('07-JAN-2005', 'dd-mon-yyyy')); insert into v values ( 6, to_date('16-JAN-2005', 'dd-mon-yyyy'), to_date('17-JAN-2005', 'dd-mon-yyyy')); insert into v values ( 7, to_date('17-JAN-2005', 'dd-mon-yyyy'), to_date('18-JAN-2005', 'dd-mon-yyyy')); insert into v values ( 8, to_date('18-JAN-2005', 'dd-mon-yyyy'), to_date('19-JAN-2005', 'dd-mon-yyyy')); insert into v values ( 9, to_date('19-JAN-2005', 'dd-mon-yyyy'), to_date('20-JAN-2005', 'dd-mon-yyyy')); insert into v values (10, to_date('21-JAN-2005', 'dd-mon-yyyy'), to_date('22-JAN-2005', 'dd-mon-yyyy')); insert into v values (11, to_date('26-JAN-2005', 'dd-mon-yyyy'), to_date('27-JAN-2005', 'dd-mon-yyyy')); insert into v values (12, to_date('27-JAN-2005', 'dd-mon-yyyy'), to_date('28-JAN-2005', 'dd-mon-yyyy')); insert into v values (13, to_date('28-JAN-2005', 'dd-mon-yyyy'), to_date('29-JAN-2005', 'dd-mon-yyyy')); insert into v values (14, to_date('29-JAN-2005', 'dd-mon-yyyy'), to_date('30-JAN-2005', 'dd-mon-yyyy'));
select c.proj_id, c.proj_start, c.proj_end, c.flag, -- -- This is what I've tried as the equivalent statement but, it is -- syntactically incorrect. What's the correct syntax for what this -- statement is intended ? -- ( select sum(t2.flag) from (select a.proj_id, a.proj_start, a.proj_end, case when ( select min(a.proj_start) from v b where (a.proj_start = b.proj_end) and (a.proj_id != b.proj_id) ) is not null then 0 else 1 end as flag from v a order by a.proj_start ) t2 where t2.proj_end <= c.proj_end ) as proj_grp from ( select a.proj_id, a.proj_start, a.proj_end, case when ( select min(a.proj_start) from v b where (a.proj_start = b.proj_end) and (a.proj_id != b.proj_id) ) is not null then 0 else 1 end as flag from v a order by a.proj_start ) c;
-
Select problem with a statement in the stored procedure oracle
Hi guys,.
I am new to oracle. I have a simple sql stored procedure that needs to be converted to oracle. The procedure is,
CREATE PROCEDURE my_procedure
Char (4) @my_var = null
AS
Select * from my_table where my_variable = @my_var
I converted this SP as oracle and the convert SP is,
create or replace
My_procedure PROCEDURE
(
v_my_var in CHAR DEFAULT NULL
)
AS
BEGIN
SELECT * FROM my_table WHERE my_variable = v_my_var;
END;
But the SP above returns an error (Error (13.3): PLS-00428: an INTO clause in the following SELECT statement) when compiling.
So I used the slider to get the results and send back them. Updated the SP is,
create or replace
My_procedure PROCEDURE
(
v_my_var in CHAR NULL by DEFAULT,
cv_1 ON SYS_REFCURSOR
)
AS
BEGIN
OPEN cv_1 to SELECT * FROM my_table WHERE my_variable = v_my_var;
END;
Now, the SP is compiled successfully and return the result set correctly. My doubt is,
What is the right way to solve the problem that I mentioned above? Is there another way to get the select query result without using a cursor?
Please advice. Thank you for your help in advance.
RAMDepends on where you are calling from SP.
I assume you are using a windows client, as you referred to SQL Server.
The .NET Oracle provider, allowing return of pl/sql types and as you return only all columns in a single line, you could change your procedure to something like this:create or replace procedure my_procedure(v_my_var in char default null ,cv_1 OUT my_Table%rowtype) as rt my_table%rowtype; begin SELECT * into rt FROM my_table WHERE my_var = v_my_var; cv_1 := rt; END my_Procedure; /
-
Details by e-mail to the people found in the select statement
Hello
I managed to send me an e-mail to test base for the first time.
However, I now require a method to be found via a SQL select with their information only email people.
for example, select statement returns the details below: -.
NAME OF APPLICATION DETAILS
Fred.Bloggs request2 details
Fred.Bloggs request4 details
Jim.Blair request3 details
I should concatenate the field IE @company.com
so
[email protected] receiving an email
"request2 details" completed
"request4 details" completed
and
[email protected] receiving an email
"Details of the request3" completed
I need help for the loop enter the full e-mail address of each person, and then send them only their data.
Thanks in advance for your help.
Wire UPDATE with news (previously the report erroneously) select sql statement
your Reported
Published by: user11962502 on December 1st, 2009 01:56
Published by: user11962502 on December 1st, 2009 02:02Hello
I don't have easy access to an Oracle instance to check it works and get the syntax right right right now but my first reaction would be to use a combination of rpad() and width as the column to be constant. This can be a you hard-code (IE, if you know what type of query will always say less than 8 characters) or ideally, first select the maximum length of the table:SELECT MAX(LENGTH(request)) + 3 INTO l_max_length FROM my_table WHERE clauses; /*Added the three to give a bit of extra space - modify to suit your needs*/
Then when you are out of the field, do something like:
message:=message || rpad(i.request,l_max_length - LENGTH(i.request));
This will ensure that everything is aligned. Of course, it only works if the email is sent in plain text and that the user is using a font to width fixed to read emails in plain text. Most people do, but do not count on it.
As before, the other option is to use an HTML table, however HTML emails are not very nice - try to stick with the plaintext if possible! :) -
Classification of the UNION by the select statement
I have an SQL statement composed of a bunch of different statements of union and I would that they sort by the first Union first, then the second, then third, etc.
SELECT *.
OF SERVICE_ADDRESS
WHERE SERVICE_ADDR_ST_NUM LIKE ('% A %')
UNION
SELECT *.
OF SERVICE_ADDRESS
WHERE SERVICE_ADDR_ST_NUM LIKE ("%B %')
UNION
SELECT *.
OF SERVICE_ADDRESS
WHERE SERVICE_ADDR_ST_NUM LIKE ('%C %')
I tried a bunch of different ways, but I get an error of invalid expression;
Can someone please show me how to sort this, so that all the results come first, then the B and the C?
I left all my other tests cause well, none of them worked lol. It's just the bare bones starting point
Thanks in advanceHello
You can do this more effectively and more easily without UNION, like this:
SELECT * FROM service_address WHERE CASE WHEN street_num LIKE '%A% THEN 1 WHEN street_num LIKE '%B% THEN 2 WHEN street_num LIKE '%C% THEN 3 END > 0 ORDER BY CASE WHEN street_num LIKE '%A% THEN 1 WHEN street_num LIKE '%B% THEN 2 WHEN street_num LIKE '%C% THEN 3 END ;
If you do not want to make the same expression BOX twice, then you can do in a subquery, but then you'd have either display the results or list all service_address columns in the SELECT clause.
-
How can disable us the selection of lines under condition
Hi Experts,
JDEV version 12.1.3.0
How can disable us the selection of lines under certain conditions.
As the lines newly unregistered should be allowing the selection of lines.
Saved lines should be disabled from the selection.
Can achieve us.
Please me advice accrdingly
Thank you
Roy
You are implementing a generic selection as shown here http://www.oracle.com/technetwork/developer-tools/adf/learnmore/23-generic-table-selection-listener-169162.pdf Manager in this handler, you check and validate the selection of our not.
Timo
-
Impossible to put the select statement
Oracle 10g
Hi gurus
I appreciate if someone can help me out, I have the sample data...
Examples of data
cases like
(
Select case_id 100 of all the double union
Select 200 double
)
,
commands like
(
Select case_id 100, 111 order_id in union double all the
Select double 200 112
),
conditions that
(
Select 300 order_id, 'TTT' double description
Union of all the
Select 111, 'LTS' double
Union of all the
Select 111, 'TTT' from dual
Union of all the
Select 111, "DAN" of the double
Union of all the
Select 111, 'XXX' of the double
)Select * from ca case, ordered oo, conditions cc
where ca.case_id = oo.case_id
and = oo.order_id cc.order_id (+)
;The query result
DESCRIPTION, ORDER_ID, CASE_ID, ORDER_ID_1, CASE_ID_1
100 100 111 111 LTS
100 100 111 111 TTT
100 100 111 111 DAN
100 100 111 111 XXX
200 200 112 NULL NULL
My output desired is as below
Desired output
DESCRIPTION, ORDER_ID, CASE_ID, ORDER_ID_1, CASE_ID_1
100 100 111 111 LTS
100 100 111 111 DAN
200 200 112 NULL NULL
So far, I've written the following query, but I get the error message...
Query so far
cases like
(
Select case_id 100 of all the double union
Select 200 double
)
,
commands like
(
Select case_id 100, 111 order_id in union double all the
Select double 200 112
),
conditions that
(
Select 300 order_id, 'TTT' double description
Union of all the
Select 111, 'LTS' double
Union of all the
Select 111, 'TTT' from dual
Union of all the
Select 111, "DAN" of the double
Union of all the
Select 111, 'XXX' of the double
)Select * from ca case, ordered oo, conditions cc
where ca.case_id = oo.case_id
and (cc.order_id (+) = oo.order_id
and description in ("LTS", "DAN")
- or (+) description = "DAN."
)
;
Rules
If order_id find in the condition array then only to search the records of the array of conditions that have conditions.description in ("LTS", "DAN")
Note
I think I can achieve this by using decode on select level, but I don't want to use decode...
Hello
You just do cc.description IN ("LTS", "DAN") is part of the outer join condition. Here's one way:
SELECT *.
From case ca
JOIN Orders oo ON oo.case_id = ca.case_id
LEFT OUTER JOIN conditions cc ON cc.order_id = oo.order_id
AND cc.description IN ('LTS', 'DAN')
;
Out, as requested:
CASE_ID CASE_ID ORDER_ID ORDER_ID DESCRIPTION
------- ------- -------- -------- ------------
100 100 111 111 LTS
DAN 100 100 111 111
200 200 112
What is the problem with DECODE? As you can see, you need this problem, but if it was the easiest way and the most effective to get the results you want, why not use it?
Maybe you are looking for
-
IPhone 5 s not charging after put 9.3.4 updated and now no battery left.
A few days ago that I updated my iphone to 9.3.4 5s since then it shows that he is in charge when it is plugged to a wall mounted or portable charger but is not fresh. And now there is no battery to turn the phone on. After charging for hours it fina
-
The backlight on my keyboard stopped working
Hello. I had my laptop for less than a week and the backlight for my keyboard stopped working. I was not able to find something to help me with this... is a simple switch to turn it on and off, or am I missing something? Thank youAlan
-
HP 15 D-009tu disk hard - 500 GB RAM - 2 GB Intel pentium 4 generation I have windows 7 Home premium 64 bit OS I downloaded all required them to drivers of this model of HP.com in India, but wireless, bluetooth, webcam, readers usd are not installing
-
Get the error message "connection Wireless not found" after re-installation of Windows vista
Original title: I reinstalled just the OS (Vista) on a Dell laptop and I get a message saying that not found wireless I'm rebvuilding a laptop Dell Inspiron 1525 using the original disks. When I try to connect to the internet, I get a message saying
-
The Volume Mixer icon disappeared.
I followed the steps to the Notification tab, and it won't allow me to check the box next to Volume.