SQL Gurus : Need Help in building SQL query

SQL Gurus,
Need your expertise to solve my below problem:
- I have a column that had comma separated data, basically there are the levels in a hierarchy. eg The same column could have the following data:
Row 1: R1L1, R1L2, R1L3
Row 2: R2L1, R2L2
Row 3: R3L1, R3L2, R3L3, R3L4
For assumption purpose lets assume that there are maximum 5 Levels
I want to put this data from this column into another table which holds the levels. I am expecting the output in another table as follows:
Col1____Col2 ____Col3____Col4____Col5
Row 1: R1L1___R1L2____R1L3____null_____null
Row 2: R2L1___R2L2____null_____null_____null
Row 3: R3L1___R3L2____R3L3____R3L4___null
How do i achieve this ? ie coverting the comma separated values in a column to separate columns. The # of values in each columns could be different as I have showb above
Regards,
pk

with t as (
           select 'R1L1, R1L2, R1L3' c1 from dual union all
           select 'R2L1, R2L2' c1 from dual union all
           select 'R3L1, R3L2, R3L3, R3L4' c1 from dual
select  substr(c1,instr(', ' || c1 || ', ',', ',1,mod(l,5) + 1),instr(', ' || c1 || ', ',', ',1,mod(l + 1,5) + 1) - instr(', ' || c1 || ', ',', ',1,mod(l,5) + 1) - 2) col1,
        substr(c1,instr(', ' || c1 || ', ',', ',1,mod(l - 1,5) + 1),instr(', ' || c1 || ', ',', ',1,mod(l,5) + 1) - instr(', ' || c1 || ', ',', ',1,mod(l - 1,5) + 1) - 2) col2,
        substr(c1,instr(', ' || c1 || ', ',', ',1,mod(l - 2,5) + 1),instr(', ' || c1 || ', ',', ',1,mod(l - 1,5) + 1) - instr(', ' || c1 || ', ',', ',1,mod(l - 2,5) + 1) - 2) col3,
        substr(c1,instr(', ' || c1 || ', ',', ',1,mod(l - 3,5) + 1),instr(', ' || c1 || ', ',', ',1,mod(l - 2,5) + 1) - instr(', ' || c1 || ', ',', ',1,mod(l - 3,5) + 1) - 2) col4,
        substr(c1,instr(', ' || c1 || ', ',', ',1,mod(l - 4,5) + 1),instr(', ' || c1 || ', ',', ',1,mod(l - 3,5) + 1) - instr(', ' || c1 || ', ',', ',1,mod(l - 4,5) + 1) - 2) col5
  from  (
         select  c1,
                 length(c1) - length(replace(c1,',')) + 5 l
           from  t
COL1                   COL2                   COL3                   COL4                   COL5
R1L3                   R1L2                   R1L1
R2L2                   R2L1
R3L4                   R3L3                   R3L2                   R3L1
SQL> SY.

Similar Messages

  • Need help in building search query

    Guys ..
    Problem Description:
    I have a huge table that is indexed using CONTEXT.
    I want to write a search query that considers the following:
    1. number of keywords match
    2. takes care of spelling mistakes, synonyms and acronyms
    3. proximity - the keywords should not be too far of each other.
    e.g. I have this phrase: "Horizontal Stabilizer Trim Brake"
    I was thinking of writing a query like:
    SELECT SCORE(1) SCORE,
    TEXT text
    FROM MY_TABLE
    WHERE CONTAINS(TEXT, '(Horz | Horizontal) ACCUM (Stab | Stabilier) ACCUM Trim ACCUM (Brk | Break)', 1) >= 0
    ORDER BY SCORE DESC
    The results doesnt look satisfactory. I have not used "near" operator as i dont know how to use it.
    Please help me as I am very much new to Oracle Text.
    -G

    Well, I'm not going to write the function for you, but we can at least talk through a general strategy.
    A lot depends on how you help your users on the front end -- for example, if they're searching a technical document, you may want to return results that aren't perfect matches but you do want to make sure the user picks 'mandatory' and 'useful' keywords in a way that lets you figure out which ones are really important. On the other hand, if you're google and have to handle queries like 'horizontal stabilizer trim brake' and 'were Pete and Jenny in the break room' then you run the risk of spending too much time looking for interesting words, almost doing a full-text search on the query trying to derive meaning.
    So I'm going to presume that you have some control over what/how the users generate their searches so that finding keywords isn't the issue.
    The plan will be to parse the query a bit to find the interesting words, clean them up, and weigh their importance, then use transformed data to build the query template to score various combinations.
    So here's some pseudocode for the function:
    function parse_query(pQueryWords in clob) returns clob as
    begin
        generate_token_list (); -- split the query into a set of individual tokens/words
        for each token in token_list
            if it's a mandatory word then accumtokenlist := accumtokenlist || ' ' || token ||'*10' -- weigh the presence of the token strongly
            if it's a useful word then accumtokenlist := accumtokenlist || ' ' || token ||'*5' -- domain-specific words are also important
            if it's a stopword or reserved word, then do not add it to the list
            if it's not on my lists, then accumtokenlist := accumtokenlist || ' ' || token
                                         and normaltokenlist := normaltokenlist ||' ' || token
        end;
        --so now, we have two lists, one for NEAR and one for ACCUM
        now build the guts of the template
            querytemplate := querytemplate || '<seq> || normaltokenlist || '</seq>';
            querytemplate := querytemplate || '<seq> || replace (accumtokenlist, ' ',' ACCUM ') || '</seq>';
            querytemplate := querytemplate || '<seq>$' || replace(normaltokenlist,' ','$') || '</seq>';
            querytemplate := querytemplate || '<seq>? || replace(replace(accumtokenlist,' ',' ?'),' ', ' accum ') || </seq>';  -- first fuzzy the words, then accum
            querytemplate := querytemplate || '<seq>? || replace(replace(normaltokenlist,' ',' ?'),' ', ' near ') || </seq>';  -- first fuzzy the words, then near
        return querytemplate
    end;So, with a 'cooked' query text that is template-friendly, all we need to do is apply a template that is aware of your inputs:
    query_Template_string := '
    <query>
       <textquery lang="ENGLISH" grammar="CONTEXT"> horizontal stabilizer*5 trim brake*10
         <progression> '
    || parse_query('horizontal stabilizer trim brake')  ||
    '     </progression>
       </textquery>
      <score datatype="INTEGER" algorithm="COUNT"/>'
    </query>So that's an example of one approach.

  • Need help to build SQl query

    Employee_table
    Emp_no Emp_name Location
    100          Ram Mumbai
    200 Shyam Delhi
    300 Jadu Bangalore
    400 Madhu Hyderabad
    500 Sidhu Kolkata
    Employee_Comm
    Emp_no Comm_flag
    100 COMM
    300 NO COMM
    500 COMM
    Note - No entry for employee 200 and 400, meand commision independent
    SQL - when input flag would be COMM the display employee records 100,500,200,400
    when input flag would be NO COMM the display employee records 300,200,400
         when input flag would be NULL the display employee records 100,200,300,400,500

    Ohh,
    Thank Karthick! I have changed the SQL to meet the need
    WITH EMPLOYEE_TABLE
    AS
        SELECT 100 EMP_NO,'RAM' EMP_NAME,'MUMBAI' LOCATION FROM DUAL UNION ALL
        SELECT 200,'SHYAM','DELHI' FROM DUAL UNION ALL
        SELECT 300,'JADU','BANGALORE' FROM DUAL UNION ALL
        SELECT 400,'MADHU','HYDERABAD' FROM DUAL UNION ALL
        SELECT 500,'SIDHU','KOLKATA' FROM DUAL
    ), EMPLOYEE_COMM
    AS
        SELECT 100 EMP_NO,'COMM' COMM_FLAG FROM DUAL UNION ALL
        SELECT 300,'NO COMM' FROM DUAL UNION ALL
        SELECT 500,'COMM' FROM DUAL
    SELECT  E1.EMP_NO, EMP_NAME, LOCATION, COMM_FLAG
    FROM    EMPLOYEE_TABLE E1, EMPLOYEE_COMM E2
    WHERE   E1.EMP_NO = E2.EMP_NO (+)
            AND (COMM_FLAG = :COMM_FLAG OR COMM_FLAG IS NULL);
    Note: Derived from Karthick's SQL
    *009*

  • Need help in building a Query in AR -Daywise Report wih separate outstandin

    Hi,
    I need to build a report in AR (AR-Daywise Report with separte outstanding)
    How to proceeed with sql query for getting the AR-Daywise Report with separte outstanding?
    Any help will be needful for me
    Thanks and Regards

    Post your question in the the Financials forum, you may get a better/faster response.
    Financials
    Financials
    Thanks,
    Hussein

  • Need Help in Building a Query

    Hi,
    I have a requirment where the table data looks like as below:
    COL_NAME      COL_NAME1
    RAW_SDP     FCT_SDP
    FILENAME     FILENAME
    SDPID     SDPID
    CDRID     CDRID
    ORIGINALCDRNODEID     ORIGINALCDRNODEID
    ORIGINALCDRID     ORIGINALCDRID
    SUBSCRIBERNUMBER     SUBSCRIBERNUMBER
    COL_NAME and COL_NAME1 are the 2 columns in the table
    RAW_SDP and FCT_SDP data is stored asTable Names.
    I want a scenario where i want to pick the data(shown below) as condition as COL_NAME='RAW_SDP'
    FILENAME
    SDPID
    CDRID
    ORIGINALCDRNODEID
    ORIGINALCDRID
    SUBSCRIBERNUMBER
    Any help will be benefitial
    Thanks and Regards

    Ok, first you need to be clear what you are referring to...
    By "excel file" are you referring to a CSV file (i.e. a flat file you can load in notepad and look at the data) or are you referring to a ".xls" file that is a MS Excel workbook?
    If it's a CSV/flat file then you should use external tables to read the data...
    http://www.psoug.org/reference/externaltab.html
    If it's a .xls workbook file then you will need to set up an ODBC connection and create it as an external database...
    e.g.
    1- Go to Control Panel>Administrative Tools>Data Sources (ODBC)>System DSN and create a data source with appropriate driver. Name it EXCL.
    2- In %ORACLE_HOME%\Network\Admin\Tnsnames.ora fie add entry:
    EXCL =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.12.0.24)(PORT = 1521))
    (CONNECT_DATA =
    (SID = EXCL)
    (HS = OK)
    Here SID is the name of data source that you have just created.
    3- In %ORACLE_HOME%\Network\Admin\Listener.ora file add:
    (SID_DESC =
    (PROGRAM = hsodbc)
    (SID_NAME = <hs_sid>)
    (ORACLE_HOME = <oracle home>)
    under SID_LIST_LISTENER like:
    SID_LIST_LISTENER =
    (SID_LIST =
    (SID_DESC =
    (SID_NAME = PLSExtProc)
    (ORACLE_HOME = d:\ORA9DB)
    (PROGRAM = extproc)
    (SID_DESC =
    (GLOBAL_DBNAME = ORA9DB)
    (ORACLE_HOME = d:\ORA9DB)
    (SID_NAME = ORA9DB)
    (SID_DESC =
    (PROGRAM = hsodbc)
    (SID_NAME = EXCL)
    (ORACLE_HOME = D:\ora9db)
    Dont forget to reload the listener
    c:\> lsnrctl reload
    4- In %ORACLE_HOME%\hs\admin create init<HS_SID>.ora. For our sid EXCL we create file initexcl.ora.
    In this file set following two parameters:
    HS_FDS_CONNECT_INFO = excl
    HS_FDS_TRACE_LEVEL = 0
    5- Now connect to Oracle database and create database link with following command:
    SQL> CREATE DATABASE LINK excl
    2 USING 'excl'
    3 /
    Database link created.
    Now you can perform query against this database like you would for any remote database.
    SQL> SELECT table_name FROM all_tables@excl;
    TABLE_NAME
    DEPT
    EMP

  • Need help on oracle sql query

    Hi team,
    Please help me on below query,
    I have table like given below
    Tran_Id  tran_date   amount. Actorid
       1.         10-apr-15.   100.         1
       2.         11-apr-15.   100.         1
       3.         11-apr-15.   900.         1
       4.         12-apr-15.   100.         1
       5.         13-apr-15.   350.         1
       6.         14-apr-15.   400.         1
    Now please find the query,
    I want all the actor ids whos tran amount
    >1500 and the  date when the tran amount
    Has breached
    Ex:
    Actor-id.  Breached-date.    Total
      1.              13-apr-15.            1900
    How can I write a query for above requirement?
    Regards,
    Rajendra

    Your solution (same as Saubhik's) is incorrect. Look at source data - multiple transactions can occur same day. Therefore, your qury will return wrong results if breached amount is 1000:
    with trans as (
    select  1  tran_Id, to_date('10-apr-15', 'dd-mon-yy') tran_date,  100 amount, 1 actorid from dual union all
    select  2,  to_date('11-apr-15', 'dd-mon-yy'), 100, 1 from dual union all
    select  3,  to_date('11-apr-15', 'dd-mon-yy'), 900, 1 from dual union all
    select  4,  to_date('12-apr-15', 'dd-mon-yy'), 100, 1 from dual union all
    select  5,  to_date('13-apr-15', 'dd-mon-yy'), 350, 1 from dual union all
    select  6,  to_date('14-apr-15', 'dd-mon-yy'), 400, 1 from dual union all
    select  7,  to_date('12-apr-15', 'dd-mon-yy'), 300, 2 from dual union all
    select  8,  to_date('13-apr-15', 'dd-mon-yy'), 1200, 2 from dual union all
    select  9,  to_date('14-apr-15', 'dd-mon-yy'), 300, 2 from dual union all
    select  10,  to_date('15-apr-15', 'dd-mon-yy'), 300, 2 from dual
    trans_running_tot as (
    select tran_id, tran_date,
      sum(amount) over (partition by actorid order by tran_date) tot_amt, actorid
    from trans
    trans_ranked as (
    select actorid,tran_id, tran_date,
      rank() over (partition by actorid order by tot_amt) rk
    from trans_running_tot
    where tot_amt > 1000
    select * from trans_ranked where rk=1
       ACTORID    TRAN_ID TRAN_DATE         RK
             1          2 11-APR-15          1 -- here total amount was only 200
             1          3 11-APR-15          1
             2          8 13-APR-15          1
    SQL>
    As you can see, 2 rows were returned for actor 1. Why? Default for analytic ORDER BY is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW. Therefore, all rows with same transation_date will fall into same window:
    SQL>  with trans as (
      2   select  1  tran_Id, to_date('10-apr-15', 'dd-mon-yy') tran_date,  100 amount, 1 actorid from dual union all
      3   select  2,  to_date('11-apr-15', 'dd-mon-yy'), 100, 1 from dual union all
      4   select  3,  to_date('11-apr-15', 'dd-mon-yy'), 900, 1 from dual union all
      5   select  4,  to_date('12-apr-15', 'dd-mon-yy'), 100, 1 from dual union all
      6   select  5,  to_date('13-apr-15', 'dd-mon-yy'), 350, 1 from dual union all
      7   select  6,  to_date('14-apr-15', 'dd-mon-yy'), 400, 1 from dual union all
      8   select  7,  to_date('12-apr-15', 'dd-mon-yy'), 300, 2 from dual union all
      9   select  8,  to_date('13-apr-15', 'dd-mon-yy'), 1200, 2 from dual union all
    10   select  9,  to_date('14-apr-15', 'dd-mon-yy'), 300, 2 from dual union all
    11   select  10,  to_date('15-apr-15', 'dd-mon-yy'), 300, 2 from dual
    12   )
    13  select tran_id, tran_date,
    14    sum(amount) over (partition by actorid order by tran_date) tot_amt, actorid
    15  from trans
    16  /
       TRAN_ID TRAN_DATE    TOT_AMT    ACTORID
             1 10-APR-15        100          1
             2 11-APR-15       1100          1
             3 11-APR-15       1100          1
             4 12-APR-15       1200          1
             5 13-APR-15       1550          1
             6 14-APR-15       1950          1
             7 12-APR-15        300          2
             8 13-APR-15       1500          2
             9 14-APR-15       1800          2
            10 15-APR-15       2100          2
    10 rows selected.
    SQL>
    So correct solution is to ORDER BY transation id. Also, just in case if amount can be 0, we should add tranaction id when ordering by sum:
    with trans as (
    select  1  tran_Id, to_date('10-apr-15', 'dd-mon-yy') tran_date,  100 amount, 1 actorid from dual union all
    select  2,  to_date('11-apr-15', 'dd-mon-yy'), 100, 1 from dual union all
    select  3,  to_date('11-apr-15', 'dd-mon-yy'), 900, 1 from dual union all
    select  4,  to_date('12-apr-15', 'dd-mon-yy'), 100, 1 from dual union all
    select  5,  to_date('13-apr-15', 'dd-mon-yy'), 350, 1 from dual union all
    select  6,  to_date('14-apr-15', 'dd-mon-yy'), 400, 1 from dual union all
    select  7,  to_date('12-apr-15', 'dd-mon-yy'), 300, 2 from dual union all
    select  8,  to_date('13-apr-15', 'dd-mon-yy'), 1200, 2 from dual union all
    select  9,  to_date('14-apr-15', 'dd-mon-yy'), 300, 2 from dual union all
    select  10,  to_date('15-apr-15', 'dd-mon-yy'), 300, 2 from dual
    trans_running_tot as (
    select tran_id, tran_date,
      sum(amount) over (partition by actorid order by tran_id) tot_amt, actorid
    from trans
    trans_ranked as (
    select actorid,tran_id, tran_date,
      rank() over (partition by actorid order by tot_amt,tran_id) rk
    from trans_running_tot
    where tot_amt > 1000
    select * from trans_ranked where rk=1
       ACTORID    TRAN_ID TRAN_DATE         RK
             1          3 11-APR-15          1
             2          8 13-APR-15          1
    SQL>
    SY.

  • Need help on a sql query

    Hi Friends,
    I am trying to load Employees and their Assignments using APIs.
    I have various columns in my staging table like Last Name, First Name, etc., but I need help in writing query in the cursor especially for columns Emp Number and Supervisor Number.
    I have data as below
    Emp_Number     Supervisor_Number
    GE0002               GE0064
    GE0064               EG0009
    EG0009               EG0001
    100009                EG0001
    EG0001               TU0001
    Cursor I write will process the data in the same order as above, but here the problem is...
    When it processes first row, it checks for supervisor GE0064 which do not exist and so it errors out.
    Similarly for second row, it checks for supervisor EG0009 which again do not exist and so it errors out.
    So in order to prevent this, the cursor should process the rows as below
    Emp_Number     Supervisor_Number
    EG0001               TU0001
    EG0009               EG0001
    GE0064               EG0009
    GE0002               GE0064
    100009                EG0001
    By this way, Supervisor should be defined first as an employee and then it can be used as a supervisor for other employees
    is there a way that I can get the output as above(second set of data), when the table has records randomly as above(first set of data)
    Appreciate your help!
    Thanks,
    Srikanth

    Srikanth wrote:
    ... but the number of records returned by above query are lot more than number of records in the table.
    Why did the number go up?
    It's something only you can find out
    Maybe some Emp have several Supervisor(s) like
    with
    t as
    (select 'GE0002' Emp,'GE0064' Supervisor from dual union all
    select 'GE0064','EG0009' from dual union all
    select 'EG0009','EG0001' from dual union all
    select 'GE0064','100009' from dual union all
    select '100009','EG0001' from dual union all
    select 'EG0001','TU0001' from dual
    select Emp,Supervisor,lpad('_',3 * (level - 1),'_')||Emp indent
      from (select Emp,Supervisor
              from t
            union all
            select supervisor,null
              from t tt
             where not exists(select null
                                from t
                               where emp = tt.supervisor
    start with Supervisor is null
    connect by prior Emp = Supervisor
    EMP
    SUPERVISOR
    INDENT
    TU0001
    TU0001
    EG0001
    TU0001
    ___EG0001
    100009
    EG0001
    ______100009
    GE0064
    100009
    _________GE0064
    GE0002
    GE0064
    ____________GE0002
    EG0009
    EG0001
    ______EG0009
    GE0064
    EG0009
    _________GE0064
    GE0002
    GE0064
    ____________GE0002
    Regards
    Etbin

  • Need Help to write SQL Query

    Hi Experts,
    I have one requirement as below.
    I have two tables say test_1 and test_2 with same structure
    Now what i want to accomplish is loop through every record in table table_1 and look for records that have no corresponding entries in table table_2 and delete these rows from table table_1.
    Thanks.

    Hi,
    SQL> create table test_1(sno number,name varchar2(10))
      2  /
    Table created.
    SQL> select * from test1
      2  /
    no rows selected
    SQL> desc test1
    Name                                      Null?    Type
    SNO                                                NUMBER
    NAME                                               VARCHAR2(10)
    SQL> insert into test1 values(1,'vijay')
      2  /
    1 row created.
    SQL> insert into test1 values(2,'vijay')
      2  /
    1 row created.
    SQL> insert into test_1 values(2,'vijay')
      2  /
    1 row created.
    SQL> insert into test_1 values(3,'vi')
      2  /
    1 row created.
    SQL> commit
      2  /
    Commit complete.
    SQL> select * from test1
      2  /
           SNO NAME
             1 vijay
             2 vijay
    SQL> select * from test_1
      2  /
           SNO NAME
             2 vijay
             3 vi
    SQL> select * from test1
      2  minus
      3  select * from test_1
      4  /
           SNO NAME
             1 vijayRegards,
    Vijayaraghavan K

  • I need help on This SQL problem ASAP :)

    Hi All,
    I need help on this....
    I have a table...
    Say table name: one
    with these values
    premnum status
    1234 C
    1234 F
    1234 P
    1234 F
    5678 C
    5678 F
    5678 P
    9112 C
    9112 F
    9112 P
    9112 F
    3456 C
    3456 F
    3456 P
    7890 C
    7890 P
    7890 F
    Now, I want to output only those premnum with status = 'C' and those premnum with Status 'F' having a count > 1 (with two status = 'F')
    So the output would be something like this
    premnum status
    1234 C
    1234 F
    1234 F
    5678 C
    9112 C
    9112 F
    9112 F
    3456 C
    7890 C
    I really need help on this asap...
    I need the SQL statement on this....
    Thank you in advance. :)
    Edited by: 804697 on Oct 23, 2010 9:45 PM

    Hi,
    you can use the following query.
    CREATE TABLE PREM_TEST ( premnum NUMBER , STATUS VARCHAR2(1));
    INSERT INTO PREM_TEST VALUES(1234 ,'C');
    INSERT INTO PREM_TEST VALUES(1234 ,'F');
    INSERT INTO PREM_TEST VALUES(1234 ,'P');
    INSERT INTO PREM_TEST VALUES(1234 ,'F');
    INSERT INTO PREM_TEST VALUES(5678 ,'C');
    INSERT INTO PREM_TEST VALUES(5678 ,'F');
    INSERT INTO PREM_TEST VALUES(5678 ,'P');
    INSERT INTO PREM_TEST VALUES(9112 ,'C');
    INSERT INTO PREM_TEST VALUES(9112 ,'F');
    INSERT INTO PREM_TEST VALUES(9112 ,'P');
    INSERT INTO PREM_TEST VALUES(9112 ,'F');
    INSERT INTO PREM_TEST VALUES(3456 ,'C');
    INSERT INTO PREM_TEST VALUES(3456 ,'F');
    INSERT INTO PREM_TEST VALUES(3456 ,'P');
    INSERT INTO PREM_TEST VALUES(7890 ,'C');
    INSERT INTO PREM_TEST VALUES(7890 ,'P');
    INSERT INTO PREM_TEST VALUES(7890 ,'F');
    SELECT     PREMNUM , STATUS
    FROM     PREM_TEST
    WHERE     STATUS = 'C'
    OR          (PREMNUM , STATUS ) IN (     SELECT PREMNUM , STATUS
                                                 FROM     PREM_TEST
                                                 WHERE     STATUS = 'F'
                                                 GROUP BY PREMNUM , STATUS
                                                 HAVING COUNT(*) > 1
    PREMNUM S
    1234 C
    1234 F
    1234 F
    5678 C
    9112 C
    9112 F
    9112 F
    3456 C
    7890 C
    9 rows selected.

  • New To Oracle.. Needs Help:: Conversion from SQL Server to Oracle 11g

    I am new to Oracle 11g and badly need the conversion of SQL Server Functions to Oracle.. Sample Pasted Code not working .. end with error.. pls help
    Create Table TempT (ID1 Varchar (10),
    ID2 Varchar (10)
    CREATE OR REPLACE PACKAGE GLOBALPKG
    AS
    TYPE RCT1 IS REF CURSOR;
    TRANCOUNT INTEGER := 0;
    IDENTITY INTEGER;
    END;
    CREATE OR REPLACE FUNCTION fTempT
    i IN VARCHAR2 DEFAULT NULL
    RETURN GLOBALPKG.RCT1
    IS
    REFCURSOR GLOBALPKG.RCT1;
    BEGIN
    OPEN REFCURSOR FOR
    SELECT TT.*
    FROM TempT TT
    WHERE (fTempT.i = ''
    OR TT.ID1 = fTempT.i)
    RETURN REFCURSOR;
    END;
    CREATE OR REPLACE FUNCTION fTempTF
    i IN VARCHAR2 DEFAULT NULL
    RETURN GLOBALPKG.RCT1
    IS
    REFCURSOR GLOBALPKG.RCT1;
    BEGIN
    OPEN REFCURSOR FOR
    SELECT *
    FROM TABLE(fTempT(i))
    RETURN REFCURSOR;
    END;
    LAST FUNCTION ENDs WITH ERROR
    Error(13,7): PL/SQL: ORA-22905: cannot access rows from a non-nested table item

    2. The major purpose is to get a simplest way to create a parameterized function who can return a table like output. 2nd function has no use instead i was testing the result of First Function like thisIf you just want to select from a select, you should use a view not a function.
    1. which program is more help ful for writing and executing queries bcoz after using Query Analyzer of Microsoft It seems difficult to work on SQL Developer.
    sqlplus? If you are having difficulty learning new tools because of an old one you used, probably best to forget the old one and concentrate on learning the new one because it will be different. This goes for the database itself also.
    2. Can DMLs be used within a Function.Yes, you just can't execute the function in another SQL statement if it modifies data and this is a good thing.
    3. Can temporary tables be used within a function.Unfortunately yes, but they shouldn't be unless you are in a slowest application competition.
    5. Each Function which is a Table Function must be accompanied with Type Definitions?? its a bit longer way of doing the things than SQL ServerThat is why it is better to use views instead, is there any reason you want a select that you can select from inside a function?
    SQL Server for last 9 years thats why i refer this toolThat is not in itself a problem, if you try and do what you did in SQLServer in Oracle, that will be a problem though.

  • New to PL/SQL and need help on check sum using ASCII function

    Hello,
    Need your expertise to help in figuring out how to write
    code to calculate using ASCII function to return value for a character. For example ASCII('A') is 58. I want to do the check sum to sum-up the value for each character in the name. For example 'Jack'
    Appreciate your help.
    CK

    Hi,
    Please post all the technical queries in the respective forums. For more details and answers in SQL and PL/SQL, use the following forum:
    PL/SQL
    Sample PL/SQL code for your requirement:
    -- make sure you have the serveroutput on using command.
    -- set serveroutput on
    DECLARE
    sumval NUMBER(10);
    tempval NUMBER(10);
    colval VARCHAR2(20);
    BEGIN
    SELECT USER INTO colval FROM dual;
    sumval := 0;
    FOR i IN 1..LENGTH(colval)
    LOOP
    SELECT ASCII(SUBSTR(colval,i,1)) INTO tempval FROM dual;
    sumval := sumval+tempval;
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('sum is: '||to_char(sumval));
    END;
    The output of this pl/sql block will be:
    sum is: 397
    Please note: ASCII('A') is 65 and not 58.
    Hope that helps.
    Savitha.
    http://otn.oracle.com/sample_code/content.html

  • Oracle SQL Newbie need help with OE Demo Schema Installation

    Hello everybody !
    I'm hoping some kind soul can help out this SQL newbie.
    First of all i've installed 10g R2 database on a PC running XP SP2.
    Oracle is installed on the root C: drive
    I'm using the SQL Fundamentals I Exam Guide and DBA Handbook (Both Oracle Press)
    as my reference.
    My problem is this.
    I installed the DB and created the demo HR schema without too much problem
    but it's the demo OE schema i'm having problems getting running and cannot
    find anywhere on the net that outlines a step by step SQL process.
    I am using SQL Plus to execute these commands.
    My questions are these:
    -For the default tablespace i specify "users" ?
    -What do i specify for the temporary tablespace ? "temp" ?
    -what directory path do i put for the data files as parameter 6 ?
    I put down "C:\oracle\product\10.2.0\db_1\demo\schema\order_entry" but i suspect it's
    the wrong thing ?
    -What do i specify for the writable directory path for the log files ?
    Is it C:\oracle\product\10.2.0\RDBMS\log
    -And what is "Specify version as parameter 8:" line ?
    I assumed it was the db version but i believe it's wrong.
    Could somebody please help me ? I've already done my CCNA and i wanted to add oracle under my belt.
    I know if i had these few things cleared up for me it would pave the way to actually enjoying learning Oracle :)
    Thank you for any assistance :)

    I installed the DB products from the companion disk and there was no specific mention of the demo schemas. Regardless... They're all there within the demo subfolder and have already created the hr schema.. I just need somebody (I'll pay if necessary) to PLEASE just answer (what would be easy to you guys my questions so i can move on.
    this is a cap from my sql plus..
    SQL*Plus: Release 10.2.0.1.0 - Production on Mon Jun 14 15:01:29 2010
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> alter user oe account unlock identified by oe;
    User altered.
    SQL>
    specify password for OE as parameter 1:
    Enter value for 1: mewfymewf
    specify default tablespeace for OE as parameter 2:
    Enter value for 2: users
    specify temporary tablespace for OE as parameter 3:
    Enter value for 3: temp
    specify password for HR as parameter 4:
    Enter value for 4: mewfymewf
    specify password for SYS as parameter 5:
    Enter value for 5: mewfymewf
    specify directory path for the data files as parameter 6:
    Enter value for 6: C:\oracle\product\10.2.0\db_1\demo\schema\order_entry
    writeable directory path for the log files as parameter 7:
    Enter value for 7: C:\oracle\product\10.2.0\db_1\RDBMS\log
    specify version as parameter 8:
    Enter value for 8: 10.2.0
    User dropped.
    old 1: CREATE USER oe IDENTIFIED BY &pass
    new 1: CREATE USER oe IDENTIFIED BY mewfymewf
    User created.
    old 1: ALTER USER oe DEFAULT TABLESPACE &tbs QUOTA UNLIMITED ON &tbs
    new 1: ALTER USER oe DEFAULT TABLESPACE users QUOTA UNLIMITED ON users
    User altered.
    old 1: ALTER USER oe TEMPORARY TABLESPACE &ttbs
    new 1: ALTER USER oe TEMPORARY TABLESPACE temp
    User altered.
    Grant succeeded.
    Connected.
    Session altered.
    Session altered.
    SP2-0310: unable to open file "C:\oracle\product\10.2.0\db_1/demo/schema/order_entry/coe_10.2.0"
    SP2-0310: unable to open file "C:\oracle\product\10.2.0\db_1/demo/schema/order_entry/loe_10.2.0"
    SP2-0310: unable to open file "C:\oracle\product\10.2.0\db_1/demo/schema/order_entry/poe_10.2.0"
    Session altered.
    ...creating subschema OC in OE
    Type created.
    Type body created.
    Table created.
    FROM inventories i, warehouses w
    ERROR at line 6:
    ORA-00942: table or view does not exist
    FROM product_information p
    ERROR at line 10:
    ORA-00942: table or view does not exist
    FROM customers c
    ERROR at line 20:
    ORA-00942: table or view does not exist
    FROM customers c
    ERROR at line 20:
    ORA-00942: table or view does not exist
    FROM customers c
    ERROR at line 20:
    ORA-00942: table or view does not exist
    FROM orders o
    ERROR at line 9:
    ORA-00942: table or view does not exist
    ON oc_orders FOR EACH ROW
    ERROR at line 2:
    ORA-00942: table or view does not exist
    TABLE order_item_list OF oc_orders FOR EACH ROW
    ERROR at line 2:
    ORA-00942: table or view does not exist
    Commit complete.
    FROM oc_product_information o
    ERROR at line 4:
    ORA-00942: table or view does not exist
    FROM oc_product_information o
    ERROR at line 4:
    ORA-00942: table or view does not exist
    FROM oc_product_information o
    ERROR at line 4:
    ORA-00942: table or view does not exist
    FROM oc_product_information o
    ERROR at line 4:
    ORA-00942: table or view does not exist
    FROM oc_product_information o
    ERROR at line 5:
    ORA-00942: table or view does not exist
    FROM oc_product_information o
    ERROR at line 4:
    ORA-00942: table or view does not exist
    FROM oc_product_information o
    ERROR at line 5:
    ORA-00942: table or view does not exist
    FROM oc_product_information o
    ERROR at line 5:
    ORA-00942: table or view does not exist
    FROM oc_product_information o
    ERROR at line 4:
    ORA-00942: table or view does not exist
    FROM oc_product_information o
    ERROR at line 4:
    ORA-00942: table or view does not exist
    FROM oc_product_information o
    ERROR at line 4:
    ORA-00942: table or view does not exist
    FROM oc_product_information o
    ERROR at line 4:
    ORA-00942: table or view does not exist
    FROM oc_product_information o
    ERROR at line 4:
    ORA-00942: table or view does not exist
    FROM oc_product_information o
    ERROR at line 4:
    ORA-00942: table or view does not exist
    FROM oc_product_information o
    ERROR at line 4:
    ORA-00942: table or view does not exist
    FROM oc_product_information o
    ERROR at line 5:
    ORA-00942: table or view does not exist
    FROM oc_product_information o
    ERROR at line 4:
    ORA-00942: table or view does not exist
    FROM oc_product_information o
    ERROR at line 4:
    ORA-00942: table or view does not exist
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    Type altered.
    3 rows updated.
    0 rows updated.
    0 rows updated.
    0 rows updated.
    Commit complete.
    Type body altered.
    Type body altered.
    Type body altered.
    PL/SQL procedure successfully completed.
    SQL>
    Like i can figure out that the "version in parameter 8" has something to do with the coe, poe & loe files
    but i don't know what.
    If somebody can please help me with my questions then i know i can move on.
    Thanks
    Edited by: user11216992 on Jun 14, 2010 3:37 PM

  • Hi all, need help in PL SQL?

    I am new in this industry. I have my training going on ORACLE PL SQL.
    Can somebody help me out:
    1.) How do we write program to add two numbers and then printing them as output.
    2.) How do we write program to read from a file and then write to another file.
    3.) How do we write program to send an email from your program.
    4.) How do we write program to create random numbers.
    Thanks in advance. . .

    Hello;
    This forum is dedicated for Oracle Beehive, if you need help and advices on SQL/PL-SQL please open a thread on the following forum: PL/SQL
    About your third question, if you want to send an email from Beehive the best way is to perform that through the Web Services.
    Fred

  • Need help with MS SQL server JDBC driver

    Anyone has experience getting ACS working with SQL2005? We keep getting ‘com.adobe.adept.persist.DatabaseException: java.sql.SQLException: No suitable driver’
    We’re using sqljdbc.jar and sqljdbc4.jar that downloaded from Microsoft website. We added this to every library folder under tomcat, JRE and SDK but it did not help. Any suggestion will be helpful.
    Thanks-

    Hi,
    We have ACS with SQL Server 2005 Std correctly working.
    We have this settings:
    ############ SQL Server Connection ############
    com.adobe.adept.persist.sql.driverClass=com.microsoft.sqlserver.jdbc.SQLServerDriver
    com.adobe.adept.persist.sql.connection=jdbc:sqlserver://ip-addressSQL:PortSQL;databaseName =Adept
    com.adobe.adept.persist.sql.dialect=microsoft
    com.adobe.adept.persist.sql.user=userSQL
    com.adobe.adept.persist.sql.password=passSQL
    Wi use Microsoft SQL Server JDBC Driver 3.0 downloaded from Microsoft website (http://www.microsoft.com/download/en/details.aspx?id=21599)
    Good luck,

  • Need Help in Simple SQL

    Hi,
    I need help. I did not know how to make this select statement run without error.
    select iif(max(numberseries) is null,'0',numberseries+ 1) from registration
    Thank

    Hi ,
    May i know what are you trying to do ,
    if you are trying to use if else in query, then it wont work
    if else is not valid in query.
    try to use decode or case , such that your need can be full filled
    Thank you
    Raj Deep.A

Maybe you are looking for

  • CS3: Page range problem

    I have a document with several short sections, 1- 4 pages each. Each section is numbered from page 1 and has a different section marker and prefix. All section prefixes are unique, so even though I have several page 1s, I have only one page AL1. Here

  • Uninstalled iphoto by accident, how can i get it back for free?

    Hi! I have a macbook pro from last year, got it around march. Back then i installed all the apps you get with macbook, imovie, garageband and iphoto. I tried iPhoto, but was completely lost and i just thought that i might as well just delete the app

  • Open documents from within

    I was a moderate user of FInal Cut Studio, but I am completely new to anything concerning Final Cut X. My apology in advance if this is obvious. I am trying to open  someone's FCS X project file on their machine, with .fcpproject extension. I double

  • Names of objects for multiple actions in different slides

    I am trying to develope an interactive software guide which requires something like a panel to insert it in each slide. This panel contains precise instructions on how tu use the interface visible in the current slide. The problem is that sometimes t

  • Create condition table

    Can anybody explain how to create a condition table in a detailed manner step by step? Thanks in advance for the answers.