Need help with a SQL qurey that returns multiple rows for one record?

I have the following query where I use a CASE WHEN clause to determine the date of a shift that begins with "FRLO" on day1 - day14 of the pay period. It works great if a schedule record contains one day that begins "FRLO", but if more than one day is "FRLO" then it only returns the first day it finds and not the others. Is there some way to get the query to return a ron for every day 1 - 14 that begins "FRLO"? System if Oracle 11G
Order of the results is not important as this is part of a larger query that orders the results.
Thanks in advance for any help,
George
SELECT s.empid,
CASE
WHEN UPPER (SUBSTR (s.Day1, 0, 4)) = 'FRLO'
THEN
pp.startpp
WHEN UPPER (SUBSTR (s.Day2, 0, 4)) = 'FRLO'
THEN
pp.startpp + 1
WHEN UPPER (SUBSTR (s.Day3, 0, 4)) = 'FRLO'
THEN
pp.startpp + 2
WHEN UPPER (SUBSTR (s.Day4, 0, 4)) = 'FRLO'
THEN
pp.startpp + 3
WHEN UPPER (SUBSTR (s.Day5, 0, 4)) = 'FRLO'
THEN
pp.startpp + 4
WHEN UPPER (SUBSTR (s.Day6, 0, 4)) = 'FRLO'
THEN
pp.startpp + 5
WHEN UPPER (SUBSTR (s.Day7, 0, 4)) = 'FRLO'
THEN
pp.startpp + 6
WHEN UPPER (SUBSTR (s.Day8, 0, 4)) = 'FRLO'
THEN
pp.startpp + 7
WHEN UPPER (SUBSTR (s.Day9, 0, 4)) = 'FRLO'
THEN
pp.startpp + 8
WHEN UPPER (SUBSTR (s.Day10, 0, 4)) = 'FRLO'
THEN
pp.startpp + 9
WHEN UPPER (SUBSTR (s.Day11, 0, 4)) = 'FRLO'
THEN
pp.startpp + 10
WHEN UPPER (SUBSTR (s.Day12, 0, 4)) = 'FRLO'
THEN
pp.startpp + 11
WHEN UPPER (SUBSTR (s.Day13, 0, 4)) = 'FRLO'
THEN
pp.startpp + 12
WHEN UPPER (SUBSTR (s.Day14, 0, 4)) = 'FRLO'
THEN
pp.startpp + 13
END
startdate,
NULL starttime,
NULL endtime,
8 hours,
0 minutes
FROM schedules s
JOIN
payperiods pp
ON pp.periodid = s.periodid
WHERE UPPER (SUBSTR (s.Day1, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day2, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day3, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day4, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day5, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day6, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day7, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day8, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day9, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day10, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day11, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day12, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day13, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day14, 0, 4)) = 'FRLO';
CURRENT OUTPUT
EMPID STARTDATE STARTTIME ENDTIME HOURS MINUTES
753738, 3/25/2013 , , ,8 ,0
753740, 3/25/2013 , , ,8 ,0
753748, 3/25/2013 , , ,8 ,0
DESIRED OUTPUT
EMPID STARTDATE STARTTIME ENDTIME HOURS MINUTES
753738, 3/25/2013 , , ,8 ,0
753740, 3/25/2013 , , ,8 ,0
753748, 3/25/2013 , , ,8 ,0
753738, 3/26/2013 , , ,8 ,0
753740, 3/26/2013 , , ,8 ,0
753740, 3/28/2013 , , ,8 ,0
753748, 1/1/2013 , , ,8 ,0
753738, 4/3/2013 , , ,8 ,0
753748, 4/3/2013 , , ,8 ,0
CREATE TABLE SCHEDULES
SCHEDULEID NUMBER(12) NOT NULL,
EMPID NUMBER(12) NOT NULL,
PERIODID VARCHAR2(6 BYTE) NOT NULL,
AREAID NUMBER(12) NOT NULL,
DAY1 VARCHAR2(50 BYTE),
DAY2 VARCHAR2(50 BYTE),
DAY3 VARCHAR2(50 BYTE),
DAY4 VARCHAR2(50 BYTE),
DAY5 VARCHAR2(50 BYTE),
DAY6 VARCHAR2(50 BYTE),
DAY7 VARCHAR2(50 BYTE),
DAY8 VARCHAR2(50 BYTE),
DAY9 VARCHAR2(50 BYTE),
DAY10 VARCHAR2(50 BYTE),
DAY11 VARCHAR2(50 BYTE),
DAY12 VARCHAR2(50 BYTE),
DAY13 VARCHAR2(50 BYTE),
DAY14 VARCHAR2(50 BYTE),
NOPTIND1 INTEGER DEFAULT 0,
NOPTIND2 INTEGER DEFAULT 0,
NOPTIND3 INTEGER DEFAULT 0,
NOPTIND4 INTEGER DEFAULT 0,
NOPTIND5 INTEGER DEFAULT 0,
NOPTIND6 INTEGER DEFAULT 0,
NOPTIND7 INTEGER DEFAULT 0,
NOPTIND8 INTEGER DEFAULT 0,
NOPTIND9 INTEGER DEFAULT 0,
NOPTIND10 INTEGER DEFAULT 0,
NOPTIND11 INTEGER DEFAULT 0,
NOPTIND12 INTEGER DEFAULT 0,
NOPTIND13 INTEGER DEFAULT 0,
NOPTIND14 INTEGER DEFAULT 0
CREATE TABLE PAYPERIODS
PERIODID VARCHAR2(6 BYTE) NOT NULL,
STARTPP DATE,
ENDPP DATE
Insert into SCHEDULES
(SCHEDULEID, EMPID, PERIODID, AREAID, DAY1,
DAY2, DAY3, DAY4, DAY5, DAY6,
DAY7, DAY8, DAY9, DAY10, DAY11,
DAY12, DAY13, DAY14, NOPTIND1, NOPTIND2,
NOPTIND3, NOPTIND4, NOPTIND5, NOPTIND6, NOPTIND7,
NOPTIND8, NOPTIND9, NOPTIND10, NOPTIND11, NOPTIND12,
NOPTIND13, NOPTIND14)
Values
(3693744, 753738, '082013', 2167, 'X',
'FRLO<1530>', 'FRLO<1530>', '1530', '1530', '1530',
'X', 'X', '1530', '1530', 'FRLO',
'1530', '1530', 'X', 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0);
Insert into SCHEDULES
(SCHEDULEID, EMPID, PERIODID, AREAID, DAY1,
DAY2, DAY3, DAY4, DAY5, DAY6,
DAY7, DAY8, DAY9, DAY10, DAY11,
DAY12, DAY13, DAY14, NOPTIND1, NOPTIND2,
NOPTIND3, NOPTIND4, NOPTIND5, NOPTIND6, NOPTIND7,
NOPTIND8, NOPTIND9, NOPTIND10, NOPTIND11, NOPTIND12,
NOPTIND13, NOPTIND14)
Values
(3693745, 753740, '082013', 2167, 'X',
'FRLO<1530>', 'FRLO<1530>', '1530', 'FRLO', '1530',
'X', 'X', '1530', '1530', '1530',
'1530', '1530', 'X', 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0);
Insert into SCHEDULES
(SCHEDULEID, EMPID, PERIODID, AREAID, DAY1,
DAY2, DAY3, DAY4, DAY5, DAY6,
DAY7, DAY8, DAY9, DAY10, DAY11,
DAY12, DAY13, DAY14, NOPTIND1, NOPTIND2,
NOPTIND3, NOPTIND4, NOPTIND5, NOPTIND6, NOPTIND7,
NOPTIND8, NOPTIND9, NOPTIND10, NOPTIND11, NOPTIND12,
NOPTIND13, NOPTIND14)
Values
(3693746, 753748, '082013', 2167, 'X',
'FRLO<1530>', '1530', '1530', '1530', '1530',
'X', 'X', 'FRLO<1530>', '1530', 'FRLO',
'1530', '1530', 'X', 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0);
COMMIT;
Insert into PAYPERIODS
(PERIODID, STARTPP)
Values
('082013', TO_DATE('03/24/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
COMMIT;

Do you have the opportunity to change the data model to have one day per row ? It would make this easier to get this result without the need for a 14-way CASE or UNION.
If not...
The case statement will return as soon as it matches one of the conditions. Since you want a match when any column in the row starts with FRLO you can use a UNION ALL treating each column as a separate result. There may be more efficient ways to do this, but here is one way:
Select S.Empid,       Pp.Startpp Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
  From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
  Where Upper (Substr (S.Day1, 0, 4)) = 'FRLO'
Union All 
Select S.Empid,       Pp.Startpp+1 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
  From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
  Where Upper (Substr (S.Day2, 0, 4)) = 'FRLO'
Union All 
Select S.Empid,       Pp.Startpp+2 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
  From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
  Where Upper (Substr (S.Day3, 0, 4)) = 'FRLO'
Union All 
Select S.Empid,       Pp.Startpp+3 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
  From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
  Where Upper (Substr (S.Day4, 0, 4)) = 'FRLO'
Union All 
Select S.Empid,       Pp.Startpp+4 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
  From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
  Where Upper (Substr (S.Day5, 0, 4)) = 'FRLO'
Union All 
Select S.Empid,       Pp.Startpp+5 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
  From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
  Where Upper (Substr (S.Day6, 0, 4)) = 'FRLO'
Union All 
Select S.Empid,       Pp.Startpp+6 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
  From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
  Where Upper (Substr (S.Day7, 0, 4)) = 'FRLO'
Union All 
Select S.Empid,       Pp.Startpp+7 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
  From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
  Where Upper (Substr (S.Day8, 0, 4)) = 'FRLO'
Union All 
Select S.Empid,       Pp.Startpp+8 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
  From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
  Where Upper (Substr (S.Day9, 0, 4)) = 'FRLO'
Union All 
Select S.Empid,       Pp.Startpp+9 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
  From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
  Where Upper (Substr (S.Day10, 0, 4)) = 'FRLO'
Union All 
Select S.Empid,       Pp.Startpp+10 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
  From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
  Where Upper (Substr (S.Day11, 0, 4)) = 'FRLO'
Union All 
Select S.Empid,       Pp.Startpp+11 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
  From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
  Where Upper (Substr (S.Day12, 0, 4)) = 'FRLO'
Union All 
Select S.Empid,       Pp.Startpp+12 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
  From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
  Where Upper (Substr (S.Day13, 0, 4)) = 'FRLO'
Union All 
Select S.Empid,       Pp.Startpp+13 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
  From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
  Where Upper (Substr (S.Day14, 0, 4)) = 'FRLO'

Similar Messages

  • On Windows 7, CS6 all products, but especially need help with ID.  Fonts that are showing in other applications are not showing in ID.

    on Windows 7, CS6 all products, but especially need help with ID.  Fonts that are showing in other applications are not showing in ID.

    The ID Program folder will be relevant to your OS...
    I took a shot and right clicked on my Scripts Samples, choose reveal in Explorer and opened up the ID Program folder.
    As shown, there is a Fonts folder.
    Drag/Copy/Paste fonts to this folder.

  • I need help with a PDF file that is an image, the "Read Out Loud' option does not work, please help!

    I need help with a PDF file that is an image, the "Read Out Loud' option does not work, please help!

    You mean an image such as a scanned document?
    If that is the case, the file doesn't contain any text for Reader Out Loud to read. In order to fix that, you would need an application such as Adobe Acrobat that does Optical Character Recognition to convert the images to actual text.
    You can also try to export the file as a Word document or something else using ExportPDF which I believe offers OCR and is cheaper than Acrobat.

  • How to create a function that returns multiple rows in table

    Dear all,
    I want to create a funtion that returns multiple rows from the table (ex: gl_balances). I done following:
    -- Create type (successfull)
    Create or replace type tp_gl_balance as Object
    PERIOD_NAME VARCHAR2(15),
    CURRENCY_CODE VARCHAR2(15),
    PERIOD_TYPE VARCHAR2(15),
    PERIOD_YEAR NUMBER(15),
    BEGIN_BALANCE_DR NUMBER,
    BEGIN_BALANCE_CR NUMBER
    -- successfull
    create type tp_tbl_gl_balance as table of tp_gl_balance;
    but i create a function for return some rows from gl_balances, i can't compile it
    create or replace function f_gl_balance(p_period varchar2) return tp_tbl_gl_balance pipelined
    as
    begin
    return
    (select gb.period_name, gb.currency_code, gb.period_type, gb.period_year, gb.begin_balance_dr, gb.begin_balance_cr
    from gl_balances gb
    where gb.period_name = p_period);
    end;
    I also try
    create or replace function f_gl_balance(p_period varchar2) return tp_tbl_gl_balance pipelined
    as
    begin
    select gb.period_name, gb.currency_code, gb.period_type, gb.period_year, gb.begin_balance_dr, gb.begin_balance_cr
    from gl_balances gb
    where gb.period_name = p_period;
    return;
    end;
    Please help me solve this function.
    thanks and best reguard

    hi,
    Use TABLE FUNCTIONS,
    [http://www.oracle-base.com/articles/9i/PipelinedTableFunctions9i.php]
    Regards,
    Danish

  • I need help with my videos now that I downloaded the ios6.  It won't play.

    I need help with my videos. I downloaded the ios6 and now they won't play.  Does anyone know how to fix?

    Wanted to let everyone know that after looking at other discussions I did a hard reboot and it is now working.  Love this site!

  • Print Child SQL which is returning multiple rows to single colum.

    I have a requirement to print both Parent and Child SQLs rows to single row.
    For Ex:
    Parent row is returning single row
    Id, Name, Primary Rate.
    101, LName,FName ,30
    Child row is returning multiple rows
    Id, Name, Secondary Rate
    101, LName,FName,15
    101, LName,FName,10
    The end result should be
    101,LName,FName,30,15,10
    Any suggestions please?

    Below is the XML TAG
    <LIST_EMPLOYEERATE>
    <EMPLOYEERATE>
    <EMPNUMBER>112</EMPNUMBER>
    <EMPNAME>Aaron</EMPNAME>
    <PAYRATE>38.09</PAYRATE>
    <JOBNAME>Technician</JOBNAME>
    <EMPTYPE>Salary</EMPTYPE>
    <LIST_ADDRATE>
    <ADDRATE>
    <ADDPAYRATE>26</ADDPAYRATE>
    </ADDRATE>
    <ADDRATE>
    <ADDPAYRATE>7.9</ADDPAYRATE>
    </ADDRATE>
    </LIST_ADDRATE>
    </EMPLOYEERATE>
    </LIST_EMPLOYEERATE>
    The Result should be (assume this is going onto excel spread sheet)
    EmpNum EmpName Rate EmpType Rate1 Rate2
    112 Aaron 38.09 Salary 26 7.9
    Using @inline we are able to get 26 and 7.9 on the same line, but how to push 7.9 to next column?
    Thanks!

  • Why no tab add-ins that enable multiple rows for Firefox 4???

    I geneally have lots of tabs open at any given time. I traditionally use TabKit, TabMix, and others that let me use multiple rows of tabs (among other options). I have not been able to find ANY add-ons that support multiple rows. There is sadness across the land.

    The mentioned "Multirow Bookmarks Toolbar Plus" add-on specifically addresses bookmarks, while the question is regarding the tabs.

  • Help! Need oracle help with constructing stored procedure that return resultsets

    Suns tutorial path for returning resultsets from stored procedures indicates that the following should work...
    CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
    ResultSet rs = cs.executeQuery();
    Thats if you build your stored procedure something like this ...
    String createProcedure = "create procedure SHOW_SUPPLIERS " + "as " + "select SUPPLIERS.SUP_NAME, COFFEES.COF_NAME " + "from SUPPLIERS, COFFEES " + "where SUPPLIERS.SUP_ID = COFFEES.SUP_ID " + "order by SUP_NAME";
    We are using oracle 8.1.6. However I've been told that with oracle procedures when you return a result set from a called procedure you return a p_cursor variable. Somthing like this
    (p_cursor in out SHOW_SUPPLIERS.SHOCurTyp)
    is
    begin
    open p_cursor for
    select * from suppliers
    In which case the above mentioned sun code doesn't work.
    We want to use jdbc to call a stored procedure that returns a resultset that does not require us to import any proprietary oracle objects...
    Is there another way to write these stored procedures, rather than using this cursor construct? Are we missing something in the way we invoke them?

    Suns tutorial path for returning resultsets from stored procedures indicates that the following should work...
    CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
    ResultSet rs = cs.executeQuery();
    Thats if you build your stored procedure something like this ...
    String createProcedure = "create procedure SHOW_SUPPLIERS " + "as " + "select SUPPLIERS.SUP_NAME, COFFEES.COF_NAME " + "from SUPPLIERS, COFFEES " + "where SUPPLIERS.SUP_ID = COFFEES.SUP_ID " + "order by SUP_NAME";
    We are using oracle 8.1.6. However I've been told that with oracle procedures when you return a result set from a called procedure you return a p_cursor variable. Somthing like this
    (p_cursor in out SHOW_SUPPLIERS.SHOCurTyp)
    is
    begin
    open p_cursor for
    select * from suppliers
    In which case the above mentioned sun code doesn't work.
    We want to use jdbc to call a stored procedure that returns a resultset that does not require us to import any proprietary oracle objects...
    Is there another way to write these stored procedures, rather than using this cursor construct? Are we missing something in the way we invoke them?

  • I need help with a backup file that was deleted and now undeleted from my hard drive

    Last month (May 6, 2011), I was updating my iPod Touch 4G with the new software that came out. I always make a backup of my iPod's data before I update it. While my iPod was updating I left my iPod and computer alone and was doing things around the house with my mom. And when I was done I went in my room to see if it was done and my computer decides that it was going to freeze and crash on me (with my iPod plugged in and stuck on the updating or verifying software mode.) I managed to get my iPod back to working condition again but losing everything on my iPod. I formatted my computer hard drive but I managed to get back the backup I lost. I need help on getting the backup into iTunes so I can get my data back. I am not Jailbroken and I plan not to Jailbreak. I however saved the backup file in a folder other than the Mobilesync folder. I am also running on Windows XP. Someone please help me and thank you in advance!

    I was able to backup my iPod and I tried to restore my iPod again and it goes through the process and everything but it restores the temporary data that I had on there. It didn't restore application data or the current photos and videos that I had saved in Camera Roll before this all had happened. It is almost like it goes back to factory settings but I have some photos that were saved on the other backup that I was temporarily running on. The backup that I am looking to restore is the only backup file in the Mobilesync folder as of right now the others are saved somewhere safe for right now. Why doesn't it restore my application data or my Camera Roll pictures and videos that I saved before my computer crashed last month? Can this problem be fixed?

  • Need help with PL/SQL functions

    Hi,
    Is there a way to compare if a set of elements is present in another set using some function?
    Example: Is it possible to find out if all words present in 'BANQUE SAFRA SA' is present in 'BANQUE JACOB SAFRA (SUISSE) SA' using some function in Oracle 9i?
    Any suggestion would be appreciated.
    Thank you,
    Anushree

    Boneist,
    your solution would giv "false positives":
    SQL&gt; with my_tab as (select 'BANQUE JACOB SAFRA (SUISSE) SA' col1 from dual union all
      2                  select 'BANQUE SAFRA (SUISSE) SB' col1 from dual union all
      3                  select 'BANQUE SAFRA SA' col1 from dual union all
      4                  select 'BANQUE SAFRANE SA' col1 from dual)
      5  -- end of mimicking your data. USE SQL below!
      6  select * from my_tab
      7  where col1 like replace('BANQUE SAFRA SA', ' ', '%');
    COL1
    BANQUE JACOB SAFRA (SUISSE) SA
    BANQUE SAFRA SA
    BANQUE SAFRANE SA  Here is a PL/SQL funcion that does not expect the words in the specific order:
    SQL> DECLARE
      2     FUNCTION strInStr(
      3        a   IN   VARCHAR2,
      4        b   IN   VARCHAR2)
      5        RETURN VARCHAR2
      6     IS
      7        i          PLS_INTEGER;
      8        startpos   PLS_INTEGER;
      9        endpos     PLS_INTEGER;
    10        word       VARCHAR2(4000);
    11     BEGIN
    12        FOR i IN 1 .. LENGTH(a) - LENGTH(REPLACE(a, ' ')) + 1 LOOP
    13           startpos := INSTR(' ' || a, ' ', 1, i);
    14           endpos := INSTR(a || ' ', ' ', 1, i);
    15           word := SUBSTR(a, startpos, endpos - startpos);
    16
    17           IF ' ' || b || ' ' NOT LIKE '% ' || word || ' %' THEN
    18              RETURN 'N';
    19           END IF;
    20        END LOOP;
    21
    22        RETURN 'Y';
    23     END;
    24  BEGIN
    25     DBMS_OUTPUT.put_line(strInStr('BANQUE SAFRA SA', 'BANQUE JACOB SAFRA (SUISSE) SA'));
    26     DBMS_OUTPUT.put_line(strInStr('SAFRA BANQUE SA', 'BANQUE JACOB SAFRA (SUISSE) SA'));
    27     DBMS_OUTPUT.put_line(strInStr('BANQUE SAFRA FRANCE', 'BANQUE JACOB SAFRA (SUISSE) SA'));
    28     DBMS_OUTPUT.put_line(strInStr('QUE SAFRA SA', 'BANQUE JACOB SAFRA (SUISSE) SA'));
    29  END;
    30  /
    Y
    Y
    N
    N

  • Need a Dynamic SQL statgement that returns multiple values.

    Hi,
    I'm using Oracle 10.1.0.5.
    In an anonymous block I have a dynamic SQL statement that finds the table name and column name that a string value resides in.
    It looks like this:
          l_sql := 'SELECT 1 FROM dual WHERE exists (SELECT 1 FROM '||
                   r.owner||'.'||r.table_name||' WHERE '||r.column_name||
                   ' = :b1)';
             EXECUTE IMMEDIATE l_sql INTO l_res USING l_contents;
             DBMS_OUTPUT.Put_Line(l_contents||' exists in '||r_owner||
                                  r.table_name||'.'||r.column_name);I'd then like to do a 'Select Distinct' to list all the other values in that column in the anonymous block,
    preferably as another dynamic SQL statement.
    How can I do this?

    user10382685 wrote:
    Hi,
    I'm using Oracle 10.1.0.5.
    In an anonymous block I have a dynamic SQL statement that finds the table name and column name that a string value resides in.
    It looks like this:
    l_sql := 'SELECT 1 FROM dual WHERE exists (SELECT 1 FROM '||
    r.owner||'.'||r.table_name||' WHERE '||r.column_name||
    ' = :b1)';
    EXECUTE IMMEDIATE l_sql INTO l_res USING l_contents;
    DBMS_OUTPUT.Put_Line(l_contents||' exists in '||r_owner||
    r.table_name||'.'||r.column_name);I'd then like to do a 'Select Distinct' to list all the other values in that column in the anonymous block,
    preferably as another dynamic SQL statement.
    How can I do this?Well, it would be nice for you to post the whole context of your present solution so we know what's going on. I'll assume r comes from a loop referencing user_tab_cols or some equivalent view.
    If so, you'll likely need to check the DATA_TYPE column.
    Keeping in mind, doing something like this is going to be pretty ridiculous if you have a large amount of distinct values ... I'm hoping/assuming this is a one off type of thing.
    declare
      type        l_date is table of date;
      v_date      l_date;
      type        l_char is table of varchar2(4000);
      v_char      l_char;
      type        l_numb is table of number;
      v_numb      l_numb;
      l_distinct_ set sys_refcursor;
    begin
      <current_code>
      open l_distinct_set for 'select distinct ' || r.column_name || ' from ' || r.owner||'.'||r.table_name;
      --expand on the data types you care about as needed, this is a BASIC set
      if r.data_type = 'DATE'
      then 
        fetch l_distinct_set bulk collect into v_date;
        <process_collection_as_wanted>
      elsif r.data_type in ('VARCHAR2', 'CHAR')
      then
        fetch l_distinct_set bulk collect into v_char;
        <process_collection_as_wanted>
      elsif r.data_type = 'NUMBER'
      then
        fetch l_distinct_set bulk collect into v_numb;
        <process_collection_as_wanted>
      end if;
      close l_distinct_set;

  • Need help with this sql query

    the following query returns me the correct no of rows:
    select col1 from tab1 where
    col1 like '%'||chr(32)||'%';
    but i need to use my query in the following form and it doesn't return any row:
    select col1 from tab1 where
    col1 IN ('%'||chr(32)||'%');
    what am I doing worng?
    thanks in advance.

    Or in 10g (just recycling another example):
    WITH t AS (SELECT 'OPTI1457' || CHR(32) col1
                 FROM dual
                UNION
               SELECT 'OPT123' || CHR(9)
                 FROM dual
                UNION
               SELECT 'OPTIM12345'
                 FROM dual
    SELECT t.*
      FROM t
    WHERE REGEXP_LIKE(t.col1, CHR(32) || '|' || CHR(9))
    ;       C.

  • Need help with pl/sql tables

    i am trying but iam not understanding this....
    Evaluate this program fragment:
    DECLARE
    TYPE user_tab_rec IS RECORD (
    db_user dba_users.username%TYPE,
    DBA_TAB dba_tables%ROWTYPE);
    TYPE user_rec_tab IS TABLE OF test_rec
    INDEX BY BINARY_INTEGER;
    Tab_rec dba_tables%ROWTYPE;
    Obj_owner dba_objects.owner%TYPE;
    begin
    (processing)
    end;
    What line will generate an error?
    1.
    TYPE user_tab_rec IS RECORD (
    2.
    db_user dba_users.username%TYPE,
    3.
    DBA_TAB dba_tables%ROWTYPE);
    4.
    TYPE user_rec_tab IS TABLE OF test_rec
    5.
    INDEX BY BINARY_INTEGER;
    6.
    Tab_rec dba_tables%ROWTYPE;
    7.
    Obj_owner dba_objects.owner%TYPE;
    The correct answer is b. The line in b attempts to define a PL/SQL TABLE TYPE using a record that contains a composite datatype, which is not allowed. Answers a, c, and d are incorrect because they will not generate any errors when compiled.
    how can line b attempt to define a pl/sql table type..........
    thank u ramsy

    The correct answer is bB? I see no B.
    Do you mean three?
    But then again
    maybe line ten.
    Because (processing) isn't
    valid syntax you see.
    I know, I know
    Let's see what'll go.
    And then we'll see
    Is it A B or C?
    SQL> r
      1  DECLARE
      2  TYPE user_tab_rec IS RECORD (
      3  db_user dba_users.username%TYPE,
      4  DBA_TAB dba_tables%ROWTYPE);
      5  TYPE user_rec_tab IS TABLE OF test_rec
      6  INDEX BY BINARY_INTEGER;
      7  Tab_rec dba_tables%ROWTYPE;
      8  Obj_owner dba_objects.owner%TYPE;
      9  begin
    10  null;
    11* end;
    TYPE user_rec_tab IS TABLE OF test_rec
    ERROR at line 5:
    ORA-06550: line 5, column 31:
    PLS-00201: identifier 'TEST_REC' must be declared
    ORA-06550: line 5, column 1:
    PL/SQL: Item ignored
    SQL> create type TEST_REC as object(a number);
      2  /
    Type created.
    SQL> DECLARE
      2  TYPE user_tab_rec IS RECORD (
      3  db_user dba_users.username%TYPE,
      4  DBA_TAB dba_tables%ROWTYPE);
      5  TYPE user_rec_tab IS TABLE OF test_rec
      6  INDEX BY BINARY_INTEGER;
      7  Tab_rec dba_tables%ROWTYPE;
      8  Obj_owner dba_objects.owner%TYPE;
      9  begin
    10  null;
    11  end;
    12  /
    PL/SQL procedure successfully completed.
    SQL> Hmmm........................
    Cheers, APC

  • Need help with recovering old account that e-mail is no longer valid.  Birth date on account is not correct.

    Does anyone know how to get an old account password when all the information on the account is not accurate and the e-mail address is no longer valid.

    If none of the following will work If you forgot your Apple ID password (which sounds likely) contact Apple support: Apple ID: Contacting Apple for help with Apple ID account security

  • Need a function that return multiple rows

    Hi,
    I need a function that should return output of this query
    SELECT b.branding_code, c.name_desc
    FROM
    development.brandings b, godot.company c
    WHERE b.company_id = c.company_id;
    This above function return 30 rows and I am not giving any input
    Function using cursor,pipeline
    Please help
    Edited by: 1008783 on Jun 6, 2013 6:40 AM

    Hi,
    1008783 wrote:
    Hi
    Table A:
    Development schema
    branding_code,company_id
    Table B:
    Gogot schema
    name_desc,...Those aren't CREATE TABLE and INSERT statements. Post something that the people who want to help you can run on their own systems to re-create the problem and test their ideas.
    o/p:
    branding_code,name_desc
    I should return these column as o/p, no i/pA query will do that. There's no need for a function.
    There are good reasons for wanting a functin. If you have one, say what it is. Explain how you plan to use the function.
    Have you tried writing a function? Post your code. What specific problems did you have?

Maybe you are looking for

  • Error ORA-01467: sort key too long

    Hi. I have just come across the error ORA-01467: sort key too long . In the Oracle documentation, the 2 line description of this error basically says that there may be too many columns or group functions in the query, so I need to reduce the number o

  • Does Foxtab PDF Converter exist, is it malware?

    Heard about a Firefox add-on named Foxtab PDF Converter, googled it, got four hits saying it was malware and pervasive (as to uninstalling it.) It is supposed to convert any file capable of being printed to PDF, which seems like a handy add-on. Is an

  • Upgrade from 2005 and 2008 R2 to 2012 SP2

    My project is getting ready to upgrade from SQL Server versions 2005 and 2008 R2 to SQL Server 2012. Is there any known issues that we should look out for? For SQL Server 2005, we are only running the Database Engine, Full text search and SQL Server

  • IMovie clips

    I think I have change the name of an event, now my project does not recognize it. There is a yellow triangle with an ! in it. Is there a way to find out what the event was named when the clip was taken out of it?

  • 10.6.4 Update causes DHCP Problem

    With 10.6.4, after putting the iMac to sleep with the power button and then re-awakening it, intermittently causes OS X DHCP to fail and OS X falls back to a self assigned IP. Rebooting OS X restores DHCP functionality. This did not happen prior to 1