Joining tables via SQL

I am trying to join two tables.  I have a documents and uploads, of which user is common.  For the user, I would like results put out from the tables where it is owned by the same user.  So if they have two records in uploads, and one in documents, it puts all of those out.  Also, how do I put out the data.  For example, if it is a document, then access the document variables?
$sql="SELECT *
FROM documents
FULL JOIN uploads
ON documents.user = uploads.user";
Error:
Sql Error: Unknown column 'documents.user' in 'on clause'

I've updated it:
$sql="SELECT *
FROM documents, uploads
WHERE documents.user = uploads.user AND documents.user='$profileIDNum'";
I get two test text files, but they have different date stamps some how.  There is only one Test Text file in uploads.  In documents, there are two records.  I noticed when I change one of the dates for the records in documents, it changes the date for the Test Text file listed.

Similar Messages

  • Joining tables with SQL in Crystal XI

    I am new to Crsytal Reports. I want to join 2 tables using a formula, which I am trying to do in SQL. I created a simple test report and I can get it to work if I don't put any fields on the report from the joined table.  ie  -  if I just use fields from "sal-rep" the report works.  As soon as I add a field from "freight" (my joined table) the report will not display anything.  (but I don't get any error messages - just a blank report).  Here is my SQL: 
    SELECT "sal-rep"."full-name","sal-rep"."invoice-nbr","freight"."misc-charge-ammount"  FROM   "PUB"."sal-rep" INNER JOIN "PUB"."FREIGHT" ON ("sal-rep"."invoice-nbr"="freight"."invoice-nbr")  WHERE  "sal-rep"."invoice-nbr"='0000189957'

    I got it to work!!!   This is the SQL I used -
    SELECT "sal_rep"."full-name", "sal_rep"."invoice-nbr", "freight"."misc-charge-ammount", "freight"."invoice-date"
    FROM   "PUB"."freight" "freight" INNER JOIN "PUB"."sal-rep" "sal_rep" ON ("freight"."invoice-nbr"="sal_rep"."invoice-nbr") AND ("freight"."invoice-date"="sal_rep"."inv-date")
    WHERE  "sal_rep"."invoice-nbr"='0000189957'
    Now when I look at the Table used in Database expert it lists -  Command and Freight.
    Before it was listing Command and Sal-Rep. 
    Not sure I understand why, but at least it's working.
    thanks for your help - really appreciated!

  • Internal PLSQL Tables Access via SQL. But how ?

    Hello,
    I want to write the result of a database query in an internal PLSQL Table. After that i would like work with this internal PLSQL Table
    in a Package/Procedure/Function.
    Important for me is to access the internal Table via SQL because i have to refactor a package wich is working with 46 Database Tables an plain SQL. I
    would like to change these DB Tables into internal PLSQL Tables.
    I have written a short example wich will explain my approach to solving this problem.
    The syntax will be accepted by the Database but my 'dbms_output.put_line' statement at the end is empty or blank.
    What do i wrong ? Would be nice if anyone can help me out.
    With best regards
    Jens
    pre work :
    create table PERSON_DB_TABLE
    (SURNAME  VARCHAR2(50),
    LASTNAME VARCHAR2(50));
    insert into PERSON_DB_TABLE values
    ('JENS','FOERSTER');
    insert into PERSON_DB_TABLE values
    ('MAX','MEIER');
    insert into PERSON_DB_TABLE values
    ('MARTHA','MUSTERMANN');
    create type PERSON_OBJECT as object (
        SURNAME  VARCHAR2(50),
        LASTNAME VARCHAR2(50));
    create type PERSON_NESTED_TABLE as table of PERSON_OBJECT;
    now my anonymous block
    declare
       v_PERSON_OBJECT        PERSON_OBJECT;
       v_PERSON_NESTED_TABLE  PERSON_NESTED_TABLE;
       v_PERSON_OBJECT_2      PERSON_OBJECT;
    begin
       for v_counter in (select SURNAME, LASTNAME into v_PERSON_OBJECT.SURNAME,
                                                                                            v_PERSON_OBJECT.LASTNAME
                                  from PERSON_DB_TABLE)
         loop
            v_PERSON_NESTED_TABLE := PERSON_NESTED_TABLE(v_PERSON_OBJECT);
         end loop;
       for v_counter in (select SURNAME, LASTNAME into v_PERSON_OBJECT_2.SURNAME,
                                                                                            v_PERSON_OBJECT_2.LASTNAME
                                  from TABLE (v_PERSON_NESTED_TABLE))
         loop
            dbms_output.put_line(v_PERSON_OBJECT_2.LASTNAME);
         end loop; 
    end;

    1386a7b8-e834-43bf-a0d4-922b548bb70b wrote:
    I need this, because my customer didn't like the idea to use Database Tables instead of Variables in the RAM. So he wants this procedure redesigned.
    As Mike says, keep this person away from your database.
    Customers should not be dictating how to implement technical solutions, they should be providing business and logical requirements.
    PL/SQL arrays/collections use expensive PGA memory, taking up valuable server resources.
    Copying data from the database to PGA memory to try and process it using PL/SQL is bad design.  SQL is designed specifically for data manipulation using database tables, so it's the ideal way to do process data... directly on database tables.

  • Joining table in GRC 10 Process Control

    Hi,
    I am trying to create a new Data Source in GRC 10 Process Control. I need to join tables AGR_1251 (main table) and AGR_USERS. I am selecting AGR_1251 as main table. However, nothing comes up when I try to select AGR_USERS as 'Related Table'. On searching AGR_USERS , the system does not return any tables. Both are transparent tables and hence can be joined. I tried using both 'Reference Tables' as well as 'Dependent Tables' .
    Can you also explain the difference between 'Reference Tables' and 'Dependent Tables'.
    Regards,

    Hi Amarnath,
    tables is used to provide the table for the CURR(currency) or QUAN (quantity) fields.
    In your case you want to join tables via foreign key(s) and therefore will have to use dependant tables.
    The search for table AGR_USERS as dependant table for AGR_1251 will not return anything since the only table
    referred as check table (for a foreign key) in AGR_1251 is AGR_DEFINES.
    I would suggest to build your query based on defined check tables (see se11) of the needed tables (in this case AGR_DEFINE is the common point of both AGR_USERS & AGR_1251).
    Kind regards,
    Pascal

  • How to convert maintenance view 'v_t001k_assign' to inner join tables

    Dear friends,
    I found I could not select the fields of view 'v_t001k_assign' using SQL, and I found there are some tables joined together as below:
    T001     MANDT     =     T001K     MANDT
    T001     BUKRS     =     T001K     BUKRS
    T001K     MANDT     =     TASSIGN_MM_T001W     MANDT
    T001K     BWKEY     =     TASSIGN_MM_T001W     BWKEY
    T001W     MANDT     =     TASSIGN_MM_T001W     MANDT
    T001W     WERKS     =     TASSIGN_MM_T001W     WERKS
    T001W_EXT     MANDT     =     TASSIGN_MM_T001W     MANDT
    T001W_EXT     WERKS     =     TASSIGN_MM_T001W     WERKS_EXT
    So how to convert this maintenance view 'v_t001k_assign' to inner join tables for SQL selection?
    Thanks a lot!
    Edited by: Qiwei Yin on May 27, 2009 10:35 AM

    Hi,
    You should use the 'Search help exit' to select the data for yourself from the database. Go into the search help maintenance screen and press F1 on field 'search help exit'; follow the links. There is actually a pretty good documentation.
    Regards, Gerd Rother

  • Using Interactive Report with SQL query accessing tables via db link

    Is there a known issue with using the interactive report in version 3.1.2.00.02 with SQL that is accessing tables via a database link? I get the error 'not all variables bound', I do not get this error when using the standard report for the same SQL?
    Thanks,
    Edited by: [email protected] on May 26, 2009 2:59 PM

    Varad,
    Good question, failed to check that. In fact there are errors. Dump file c:\oraclexe\app\oracle\admin\xe\bdump\xe_s002_3640.trc
    Mon Jun 15 08:48:11 2009
    ORACLE V10.2.0.1.0 - Production vsnsta=0
    vsnsql=14 vsnxtr=3
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    Windows XP Version V5.1 Service Pack 3
    CPU : 2 - type 586, 1 Physical Cores
    Process Affinity : 0x00000000
    Memory (Avail/Total): Ph:1051M/2038M, Ph+PgF:2273M/3934M, VA:1302M/2047M
    Instance name: xe
    Redo thread mounted by this instance: 1
    Oracle process number: 16
    Windows thread id: 3640, image: ORACLE.EXE (S002)
    *** ACTION NAME:(PAGE 2) 2009-06-15 08:48:11.743
    *** MODULE NAME:(APEX:APPLICATION 112) 2009-06-15 08:48:11.743
    *** SERVICE NAME:(SYS$USERS) 2009-06-15 08:48:11.743
    *** CLIENT ID:(ADMIN:232384011651572) 2009-06-15 08:48:11.743
    *** SESSION ID:(24.931) 2009-06-15 08:48:11.743
    *** 2009-06-15 08:48:11.743
    ksedmp: internal or fatal error
    ORA-07445: exception encountered: core dump [ACCESS_VIOLATION] [_LdiDateFromArray+55] [PC:0x608B04F3] [ADDR:0x0] [UNABLE_TO_WRITE] []
    Current SQL statement for this session:
    select Stage,Procedure,Stp,FW,Reslt,MSG,date_run
    from bi_msg_VW@dwitnm
    order by 1
    ----- PL/SQL Call Stack -----
    object line object
    handle number name
    2FE1EA14 1207 package body SYS.DBMS_SYS_SQL
    2FE1F064 328 package body SYS.DBMS_SQL
    2ABDC520 5097 package body APEX_030200.WWV_RENDER_REPORT3
    2BD5E55C 1538 package body APEX_030200.WWV_FLOW_DISP_PAGE_PLUGS
    2BD5E55C 366 package body APEX_030200.WWV_FLOW_DISP_PAGE_PLUGS
    335BDA88 11190 package body APEX_030200.WWV_FLOW
    2BDBD1C8 255 procedure APEX_030200.F
    2AB58D10 30 anonymous block
    ----- Call Stack Trace -----
    I didn't include the call stack, it is too large. Now I'm even more puzzled that the IR would work while a sql report would fail.
    Bob

  • How to provide joins between oracle tables and sql server tables

    Hi,
    I have a requirement that i need to generate a report form two different data base. i.e Oracle and Sql Server.
    how to provide joins between oracle tables and sql server tables ? Any help on this
    Regards,
    Malli

    user10675696 wrote:
    I have a requirement that i need to generate a report form two different data base. i.e Oracle and Sql Server. Bad idea most times. Heterogeneous joins do not exactly scale and performance can be severely degraded by network speed and b/w availability. And there is nothing you can do in the application and database layers to address performance issue at the network level in this case - your code's performance is simply at the mercy of network performance. With a single glaring fact - network performance is continually degrading. All the time. Always. Until it is upgraded. When the performance degradation starts all over again.
    If the tables are not small (few 1000 rows each) and row volumes static, I would not consider doing a heterogeneous join. Instead I would rather go for a materialised view on the Oracle side, use a proper table and index structure, and do a local database join.

  • Tables created via SQL...

    There is a way to show information stored in a table creadted via SQL in the SBO Print Forms ?

    Hello!
    yes, this will work as such, but might not give you the
    correct values as there is no link between the table and the layout! Usually, it pulls simply the first value in the table.
    Or, you might be lucky that it works now, but not after an upgrade.
    Be careful when adding field with "ALT", if you encounter problems at any stage, you will not receive any support!
    When adding fields via "ALT", check if you can create manual links between the table and the layout via "next segment" and "link to".
    Kind regards

  • How to join two pl/sql tables .,.,,Urgent pls help

    Hi,
    Please tell me how to join to pl/sql tables with example
    thanks
    asp

    If your main intention is to get the common records/or getting whole records from the 2 different pl/sql arrays then , pls check this piece of code & explanation
    The SQL language has long offered the ability to apply set operations (UNION, INTERSECT, and MINUS) to the result sets of queries. In Oracle Database 10g, you can now use those same high-level, very powerful operators against nested tables (and only nested tables) in your PL/SQL programs and on nested tables declared as columns inside relational tables.
    Let's take a look at some of the syntax needed to do this, starting with UNION.
    First, I create a schema-level nested table type:
    CREATE OR REPLACE TYPE strings_nt
    IS TABLE OF VARCHAR2(100);
    Then I define a package and within it create and populate two nested tables of this type, each containing some of my father's and my favorite things:
    CREATE OR REPLACE PACKAGE favorites_pkg
    IS
    my_favorites strings_nt
    := strings_nt ('CHOCOLATE'
    , 'BRUSSEL SPROUTS'
    , 'SPIDER ROLL'
    dad_favorites strings_nt
    := strings_nt ('PICKLED HERRING
    , 'POTATOES'
    , 'PASTRAMI'
    , 'CHOCOLATE'
    PROCEDURE show_favorites (
    title_in IN VARCHAR2
    , favs_in IN strings_nt
    END;
    In this package, I also include a procedure to show the contents of a strings_nt nested table. This will come in very handy shortly.
    By defining these collections in a package, outside any program, they persist (they maintain their state and values) for the duration of my session or until I change or delete them. This means that I can now write programs outside the package to manipulate the contents of those collections.
    Note that this package has been simplified for the purposes of presenting collection functionality. In a production application, you should always take care to "hide" your package data, as with these collections, in the package body, and then provide procedures and functions to manage the data.
    Suppose, for example, that I would like to combine these two collections into a single collection of our favorites. Prior to Oracle Database 10g, I would have to write a loop that transfers the contents of one collection to another. Now, I can rely on the MULTISET UNION operator, as shown below:
    DECLARE
    our_favorites
    strings_nt := strings_nt ();
    BEGIN
    our_favorites :=
    favorites_pkg.my_favorites
    MULTISET UNION ---- Use INTERSECT , if you want to know common records
    favorites_pkg.dad_favorites;
    favorites_pkg.show_favorites (
    'ME then DAD', our_favorites);
    END;
    The output from this script is:
    ME then DAD
    1 = CHOCOLATE
    2 = BRUSSEL SPROUTS
    3 = SPIDER ROLL
    4 = PICKLED HERRING
    5 = POTATOES
    6 = PASTRAMI
    7 = CHOCOLATE
    ------------------------------

  • Sql statement for join tables

    hi there..i need ur helps
    Here are my tables n column name for each tables
    a) rep_arrngt
    Name
    REP_ARRNGT_ID
    REP_ARRNGT_DESC
    REP_ARRNGT_TYPE
    ACCT_CAT
    DEF_INDUSTRY_CODE
    MEDIA_ID
    LANGUAGE_ID
    CURRENCY
    PAGE_ID
    b) bci_rep_arrng
    Name
    REP_ARRNGT_ID
    BCI
    SUB_SUM_CODE
    DP_SUB_SUM_CODE
    c) acct_rep_arrngt_link
    Name
    ACCT_NO
    REP_ARRNGT_ID
    DOC_TYPE
    LAST_BILL_DATE
    BILL_FREQUENCY
    SCALING
    EFF_FROM_DATE
    EFF_TO_DATE
    MEDIA_ID
    Actually, i want to get the unique value for sub_sum_code according to the bci..
    i already use join tables n here is my sql statement :
    SELECT T1.SUB_SUM_CODE,T1.BCI,T1.REP_ARRNGT_ID,T2.REP_ARRNGT_ID,T3.REP_ARRNGT_ID FROM BCI_REP_ARRNG T1, REP_ARRNGT T2, ACCT_REP_ARRNGT_LINK T3 WHERE T1.REP_ARRNGT_ID=T2.REP_ARRNGT_ID AND T2.REP_ARRNGT_ID=T3.REP_ARRNGT_ID AND BCI='TTA00F06'
    n my results is :
    SUB_SUM_CODE BCI REP_ARRNGT_ID
    TBGSR TTA00F06 R1
    TBGSR TTA00F06 R1
    TBGSR TTA00F06 R1
    TBGSR TTA00F06 R1
    I get the repeated results for sub_sum_code..
    so, what i need to do if i want only 1 row results like this :
    [u]SUB_SUM_CODE BCI REP_ARRNGT_ID
    TBGSR TTA00F06 R1
    i try to use group by, but i get the error..plz help me

    If you only want "to get the unique value for sub_sum_code according to the bci" then why are you joining the tables in the first place? Not knowing PKs etc you could just use DISTINCT in your select statement.
    SELECT DISTINCT T1.SUB_SUM_CODE,
                    T1.BCI
    FROM BCI_REP_ARRNG T1
    AND BCI='TTA00F06'

  • 10g: parallel pipelined table func. using table(cast(SQL collect.))?

    Hi,
    i try to distribute SQL data objects - stored in a SQL data type TABLE OF <object-Type> - to multiple (parallel) instances of a table function,
    by passing a CURSOR(...) to the table function, which selects from the SQL TABLE OF storage via "select * from TABLE(CAST(<storage> as <storage-type>)".
    But oracle always only uses a single table function instance :-(
    whatever hints i provide or setting i use for the parallel table function (parallel_enable ...)
    Could it be, that this is due to the fact, that my data are not
    globally available, but only in the main thread data?
    Can someone confirm, that it's not possible to start multiple parallel table functions
    for selecting on SQL data type TABLE OF <object>storages?
    Here's an example sqlplus program to show the issue:
    -------------------- snip ---------------------------------------------
    set serveroutput on;
    drop table test_table;
    drop type ton_t;
    drop type test_list;
    drop type test_obj;
    create table test_table
         a number(19,0),
         b timestamp with time zone,
         c varchar2(256)
    create or replace type test_obj as object(
         a number(19,0),
         b timestamp with time zone,
         c varchar2(256)
    create or replace type test_list as table of test_obj;
    create or replace type ton_t as table of number;
    create or replace package test_pkg
    as
         type test_rec is record (
              a number(19,0),
              b timestamp with time zone,
              c varchar2(256)
         type test_tab is table of test_rec;
         type test_cur is ref cursor return test_rec;
         function TF(mycur test_cur)
    return test_list pipelined
    parallel_enable(partition mycur by hash(a));
    end;
    create or replace package body test_pkg
    as
         function TF(mycur test_cur)
    return test_list pipelined
    parallel_enable(partition mycur by hash(a))
    is
              sid number;
              counter number(19,0) := 0;
              myrec test_rec;
              mytab test_tab;
              mytab2 test_list := test_list();
         begin
              select userenv('SID') into sid from dual;
              dbms_output.put_line('test_pkg.TF( sid => '''|| sid || ''' ): enter');
              loop
                   fetch mycur into myRec;
                   exit when mycur%NOTFOUND;
                   mytab2.extend;
                   mytab2(mytab2.last) := test_obj(myRec.a, myRec.b, myRec.c);
              end loop;
              for i in mytab2.first..mytab2.last loop
                   -- attention: saves own SID in test_obj.a for indication to caller
                   --     how many sids have been involved
                   pipe row(test_obj(sid, mytab2(i).b, mytab2(i).c));
                   counter := counter + 1;
              end loop;
              dbms_output.put_line('test_pkg.TF( sid => '''|| sid || ''' ): exit, piped #' || counter || ' records');
         end;
    end;
    declare
         myList test_list := test_list();
         myList2 test_list := test_list();
         sids ton_t := ton_t();
    begin
         for i in 1..10000 loop
              myList.extend; myList(myList.last) := test_obj(i, sysdate, to_char(i+2));
         end loop;
         -- save into the real table
         insert into test_table select * from table(cast (myList as test_list));
         dbms_output.put_line(chr(10) || 'copy ''mylist'' to ''mylist2'' by streaming via table function...');
         select test_obj(a, b, c) bulk collect into myList2
         from table(test_pkg.TF(CURSOR(select /*+ parallel(tab,10) */ * from table(cast (myList as test_list)) tab)));
         dbms_output.put_line('... saved #' || myList2.count || ' records');
         select distinct(tab.a) bulk collect into sids from table(cast (myList2 as test_list)) tab;
         dbms_output.put_line('worker thread''s sid list:');
         for i in sids.first..sids.last loop
              dbms_output.put_line('sid #' || sids(i));
         end loop;
         dbms_output.put_line(chr(10) || 'copy physical ''test_table'' to ''mylist2'' by streaming via table function:');
         select test_obj(a, b, c) bulk collect into myList2
         from table(test_pkg.TF(CURSOR(select /*+ parallel(tab,10) */ * from test_table tab)));
         dbms_output.put_line('... saved #' || myList2.count || ' records');
         select distinct(tab.a) bulk collect into sids from table(cast (myList2 as test_list)) tab;
         dbms_output.put_line('worker thread''s sid list:');
         for i in sids.first..sids.last loop
              dbms_output.put_line('sid #' || sids(i));
         end loop;
    end;
    -------------------- snap ---------------------------------------------
    Here's the output:
    -------------------- snip ---------------------------------------------
    copy 'mylist' to 'mylist2' by streaming via table function...
    test_pkg.TF( sid => '98' ): enter
    test_pkg.TF( sid => '98' ): exit, piped #10000 records
    ... saved #10000 records
    worker thread's sid list:
    sid #98 -- ONLY A SINGLE SID HERE!
    copy physical 'test_table' to 'mylist2' by streaming via table function:
    ... saved #10000 records
    worker thread's sid list:
    sid #128 -- A LIST OF SIDS HERE!
    sid #141
    sid #85
    sid #125
    sid #254
    sid #101
    sid #124
    sid #109
    sid #142
    sid #92
    PL/SQL procedure successfully completed.
    -------------------- snap ---------------------------------------------
    I posted it to newsgroup comp.databases.oracle.server.
    (summary: "10g: parallel pipelined table functions with cursor selecting from table(cast(SQL collection)) doesn't work ")
    But i didn't get a response.
    There i also wrote some background information about my application:
    -------------------- snip ---------------------------------------------
    My application has a #2 steps/stages data selection.
    A 1st select for minimal context base data
    - mainly to evaluate for due driving data records.
    And a 2nd select for all the "real" data to process a context
    (joining much more other tables here, which i don't want to do for non-due records).
    So it's doing stage #1 select first, then stage #2 select - based on stage #1 results - next.
    The first implementation of the application did the stage #1 select in the main session of the pl/sql code.
    And for the stage #2 select there was done a dispatch to multiple parallel table functions (in multiple worker sessions) for the "real work".
    That worked.
    However there was a flaw:
    Between records from stage #1 selection and records from stage #2 selection there is a 1:n relation (via key / foreign key relation).
    Means, for #1 resulting record from stage #1 selection, there are #x records from stage #2 selection.
    That forced me to use "cluster curStage2 by (theKey)".
    Because the worker sessions need to evaluate the all-over status for a context of #1 record from stage #1 and #x records from stage #2
    (so it needs to have #x records of stage #2 together).
    This then resulted in delay for starting up the worker sessions (i didn't find a way to get rid of this).
    So i wanted to shift the invocation of the worker sessions to the stage #1 selection.
    Then i don't need the "cluster curStage2 by (theKey)" anymore!
    But: i also need to do an update of the primary driving data!
    So the stage #1 select is a 'select ... for update ...'.
    But you can't use such in CURSOR for table functions (which i can understand, why it's not possible).
    So i have to do my stage #1 selection in two steps:
    1. 'select for update' by main session and collect result in SQL collection.
    2. pass collected data to parallel table functions
    And for 2. i recognized, that it doesn't start up multiple parallel table function instances.
    As a work-around
    - if it's just not possible to start multiple parallel pipelined table functions for dispatching from 'select * from TABLE(CAST(... as ...))' -
    i need to select again on the base tables - driven by the SQL collection data.
    But before i do so, i wanted to verify, if it's really not possible.
    Maybe i just miss a special oracle hint or whatever you can get "out of another box" :-)
    -------------------- snap ---------------------------------------------
    - many thanks!
    rgds,
    Frank

    Hi,
    i try to distribute SQL data objects - stored in a SQL data type TABLE OF <object-Type> - to multiple (parallel) instances of a table function,
    by passing a CURSOR(...) to the table function, which selects from the SQL TABLE OF storage via "select * from TABLE(CAST(<storage> as <storage-type>)".
    But oracle always only uses a single table function instance :-(
    whatever hints i provide or setting i use for the parallel table function (parallel_enable ...)
    Could it be, that this is due to the fact, that my data are not
    globally available, but only in the main thread data?
    Can someone confirm, that it's not possible to start multiple parallel table functions
    for selecting on SQL data type TABLE OF <object>storages?
    Here's an example sqlplus program to show the issue:
    -------------------- snip ---------------------------------------------
    set serveroutput on;
    drop table test_table;
    drop type ton_t;
    drop type test_list;
    drop type test_obj;
    create table test_table
         a number(19,0),
         b timestamp with time zone,
         c varchar2(256)
    create or replace type test_obj as object(
         a number(19,0),
         b timestamp with time zone,
         c varchar2(256)
    create or replace type test_list as table of test_obj;
    create or replace type ton_t as table of number;
    create or replace package test_pkg
    as
         type test_rec is record (
              a number(19,0),
              b timestamp with time zone,
              c varchar2(256)
         type test_tab is table of test_rec;
         type test_cur is ref cursor return test_rec;
         function TF(mycur test_cur)
    return test_list pipelined
    parallel_enable(partition mycur by hash(a));
    end;
    create or replace package body test_pkg
    as
         function TF(mycur test_cur)
    return test_list pipelined
    parallel_enable(partition mycur by hash(a))
    is
              sid number;
              counter number(19,0) := 0;
              myrec test_rec;
              mytab test_tab;
              mytab2 test_list := test_list();
         begin
              select userenv('SID') into sid from dual;
              dbms_output.put_line('test_pkg.TF( sid => '''|| sid || ''' ): enter');
              loop
                   fetch mycur into myRec;
                   exit when mycur%NOTFOUND;
                   mytab2.extend;
                   mytab2(mytab2.last) := test_obj(myRec.a, myRec.b, myRec.c);
              end loop;
              for i in mytab2.first..mytab2.last loop
                   -- attention: saves own SID in test_obj.a for indication to caller
                   --     how many sids have been involved
                   pipe row(test_obj(sid, mytab2(i).b, mytab2(i).c));
                   counter := counter + 1;
              end loop;
              dbms_output.put_line('test_pkg.TF( sid => '''|| sid || ''' ): exit, piped #' || counter || ' records');
         end;
    end;
    declare
         myList test_list := test_list();
         myList2 test_list := test_list();
         sids ton_t := ton_t();
    begin
         for i in 1..10000 loop
              myList.extend; myList(myList.last) := test_obj(i, sysdate, to_char(i+2));
         end loop;
         -- save into the real table
         insert into test_table select * from table(cast (myList as test_list));
         dbms_output.put_line(chr(10) || 'copy ''mylist'' to ''mylist2'' by streaming via table function...');
         select test_obj(a, b, c) bulk collect into myList2
         from table(test_pkg.TF(CURSOR(select /*+ parallel(tab,10) */ * from table(cast (myList as test_list)) tab)));
         dbms_output.put_line('... saved #' || myList2.count || ' records');
         select distinct(tab.a) bulk collect into sids from table(cast (myList2 as test_list)) tab;
         dbms_output.put_line('worker thread''s sid list:');
         for i in sids.first..sids.last loop
              dbms_output.put_line('sid #' || sids(i));
         end loop;
         dbms_output.put_line(chr(10) || 'copy physical ''test_table'' to ''mylist2'' by streaming via table function:');
         select test_obj(a, b, c) bulk collect into myList2
         from table(test_pkg.TF(CURSOR(select /*+ parallel(tab,10) */ * from test_table tab)));
         dbms_output.put_line('... saved #' || myList2.count || ' records');
         select distinct(tab.a) bulk collect into sids from table(cast (myList2 as test_list)) tab;
         dbms_output.put_line('worker thread''s sid list:');
         for i in sids.first..sids.last loop
              dbms_output.put_line('sid #' || sids(i));
         end loop;
    end;
    -------------------- snap ---------------------------------------------
    Here's the output:
    -------------------- snip ---------------------------------------------
    copy 'mylist' to 'mylist2' by streaming via table function...
    test_pkg.TF( sid => '98' ): enter
    test_pkg.TF( sid => '98' ): exit, piped #10000 records
    ... saved #10000 records
    worker thread's sid list:
    sid #98 -- ONLY A SINGLE SID HERE!
    copy physical 'test_table' to 'mylist2' by streaming via table function:
    ... saved #10000 records
    worker thread's sid list:
    sid #128 -- A LIST OF SIDS HERE!
    sid #141
    sid #85
    sid #125
    sid #254
    sid #101
    sid #124
    sid #109
    sid #142
    sid #92
    PL/SQL procedure successfully completed.
    -------------------- snap ---------------------------------------------
    I posted it to newsgroup comp.databases.oracle.server.
    (summary: "10g: parallel pipelined table functions with cursor selecting from table(cast(SQL collection)) doesn't work ")
    But i didn't get a response.
    There i also wrote some background information about my application:
    -------------------- snip ---------------------------------------------
    My application has a #2 steps/stages data selection.
    A 1st select for minimal context base data
    - mainly to evaluate for due driving data records.
    And a 2nd select for all the "real" data to process a context
    (joining much more other tables here, which i don't want to do for non-due records).
    So it's doing stage #1 select first, then stage #2 select - based on stage #1 results - next.
    The first implementation of the application did the stage #1 select in the main session of the pl/sql code.
    And for the stage #2 select there was done a dispatch to multiple parallel table functions (in multiple worker sessions) for the "real work".
    That worked.
    However there was a flaw:
    Between records from stage #1 selection and records from stage #2 selection there is a 1:n relation (via key / foreign key relation).
    Means, for #1 resulting record from stage #1 selection, there are #x records from stage #2 selection.
    That forced me to use "cluster curStage2 by (theKey)".
    Because the worker sessions need to evaluate the all-over status for a context of #1 record from stage #1 and #x records from stage #2
    (so it needs to have #x records of stage #2 together).
    This then resulted in delay for starting up the worker sessions (i didn't find a way to get rid of this).
    So i wanted to shift the invocation of the worker sessions to the stage #1 selection.
    Then i don't need the "cluster curStage2 by (theKey)" anymore!
    But: i also need to do an update of the primary driving data!
    So the stage #1 select is a 'select ... for update ...'.
    But you can't use such in CURSOR for table functions (which i can understand, why it's not possible).
    So i have to do my stage #1 selection in two steps:
    1. 'select for update' by main session and collect result in SQL collection.
    2. pass collected data to parallel table functions
    And for 2. i recognized, that it doesn't start up multiple parallel table function instances.
    As a work-around
    - if it's just not possible to start multiple parallel pipelined table functions for dispatching from 'select * from TABLE(CAST(... as ...))' -
    i need to select again on the base tables - driven by the SQL collection data.
    But before i do so, i wanted to verify, if it's really not possible.
    Maybe i just miss a special oracle hint or whatever you can get "out of another box" :-)
    -------------------- snap ---------------------------------------------
    - many thanks!
    rgds,
    Frank

  • How to determine via SQL who created the sales order

    Hello I am trying to determine via SQL who created the Sales Order.  I'm looking at the ADOC table but having a hard time determining which record points to the sales order creation.

    Hi Jimmy,
    Try this:
    select
         T0.[DocNum], T2.[DocDate], T2.[CardCode], T2.[CardName],
         T1.U_NAME as [User Name], T2.UpdateDate as [Cancelled Date]
    from
         ORDR T0
         inner join OUSR T1 on T0.UserSign = T1.UserID
         inner join ADOC T2 on T0.DocNum = T2.DocNum
    where
         T2.LogInstanc = (select min(LogInstanc) from ADOC T3 where T3.ObjType = 17 and T3.DocNum = T0.DocNum and T3.CANCELED = 'Y')
         and T2.CANCELED = 'Y'
         and T2.ObjType = 17
    group by
         T0.DocNum, T2.DocDate, T2.CardCode, T2.CardName, T1.U_NAME, T2.UpdateDate
    Kind Regards,
    Owen

  • Joining tables : Smart Access Connection

    Here's my scenario...
    I have data from 1 system existing as standard HANA tables.
    I have data from a second system, coming into HANA as a Smart Access Connection.
    My task is to build queries against each system's tables to obtain relevant data from each system, and then a top level query to join system A data to system B data.
    I'm from a SQL Server background, so my natural instinct is to NOT to join tables from linked servers directly to 'local' tables.
    I would normally query the remote source, stage the required data into a local temporary table, and then join local-to-local.
    However, I am unsure as to the best approach in this new world of HANA.
    I did some reading here : SAP HANA Smart Data Access - Using the SAP HANA Database - SAP Library
    "SAP HANA Smart Data Access optimizes execution of queries by moving processing as far as possible to the database connected via SAP HANA Smart Data Access. The SQL queries then work in SAP HANA on virtual tables. The SAP HANA Query Processor optimizes the queries and executes the relevant part in the connected database, returns the result to SAP HANA and completes the operation"
    .. but this is still a bit vague to me, and I am not sure that it was intended to be read in relation to simply querying the remote connection in isolation, or in queries involving other sources as well.
    Would anyone be able to clarify, or point me to better suited reading material ?
    many thanks for any pointers on this ....

    Not possible within SQL Dev.
    It pains me to suggest this.. but the simplest thing to do is to use an external table in Access to link to Oracle and make your joins in Access. I used to do it all the time and access is fairly good at only grabbing what is necessary from oracle. The only other product that comes to mind that does this type of operation is crystal reports.

  • Group by languages in multilingual table in sql server

    Hi ,
    I am having a multilingual table in SQL server 2008 , the table has two columns ID and Text
    The text column has English, Chinese and other language texts.
    I need a resultset grouped by the languages and count of id like
    Language   count_of_id
    English          25
    Chinese         10
    other languages 3
    Is this possible? Can you please help me?

    Good day SqlServer_learn
    I have a saying that I always uses: anything is possible in developing, if you have the appropriate resources (change the existing solution could be part of the way to solve...)
    regarding your question, there is simple solution, but for most cases, I highly recommend to change the table structure and add a column for the culture of the text (like: en-us for english,
    he-il for Hebrew and so on..).
    Since you are using unicode column like nvarchar to store multi language text,
    we can get the language from the text itself, as long as it include characters from that language (text which include only numbers for example we we consider as default language since it is the same in all languages). 
    step 1: First you need an accessory table (Named like UnicodeMapping) which include all unicode characters and the number of the char in unicode (a mapping unicode table). You can use ranges as well, but
    it will be faster for the queries if you actually have all the characters, and not just range.
    For example this table (I added English and Hebrew... Do the same with all the languages that you need):
    create table UnicodeMapping (Charecter nchar(1), UnicodeNum int, CultureN NVARCHAR(100), CollateN NVARCHAR(100))
    GO
    -- fill the table with main Hebrew characters, using a number table
    insert UnicodeMapping (Charecter, UnicodeNum, CultureN, CollateN)
    select NCHAR(n), n, 'He-IL', 'Hebrew_CI_AS'
    from _ArielyAccessoriesDatabase.dbo.ArielyNumbers
    where
    n between 1488 and 1514 -- Hebrew
    or n between 64304 and 64330 -- Hebrew
    GO
    -- fill the table with main English characters, using a number table
    insert UnicodeMapping (Charecter, UnicodeNum, CultureN, CollateN)
    select NCHAR(n), n, 'En-US', 'SQL_Latin1_General_CP1_CI_AS'
    from _ArielyAccessoriesDatabase.dbo.ArielyNumbers
    where
    n between 97 and 122 -- En
    or n between 65 and 90 -- En
    GO
    -- Do the same with all the languages that you need, and all the UNICODE ranges for those languages
    select * from UnicodeMapping
    GO
    Step 2: You can create a function which get NVARCHAR as input and return the culture as output, or work directly on the data using JOIN your table and this table.
    Assuming that each row is in specific language, In order to recognize the language, you just need to check 1 character from the original string (a text character and not a number for example which might be in any language) and examine which language this
    single character is, using the our UnicodeMapping.
    You can check this thread to see an implementation of this idea: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/ccc1d16f-926f-46c8-8579-b2eecf661e7c/sort-miultiple-language-data-in-sql-serevr-by-collation?forum=transactsql
    * dont forget to add to the table all the characters like numbers and chose them as your default language
    * in the link above I just select the first character using LEFT, but if the text start with number for example then you will get default language. If you sure that the text must start with real language character then it is best solution, but if not, than
    It is better to use a "user defined function" which will find the first character that is not in the default language. if the function do not find any char in non-default language than it return default language, else it check the language using
    the UnicodeMapping and return it.
      Ronen Ariely
     [Personal Site]    [Blog]    [Facebook]

  • Cannot edit an existing table in sql server 2012

    Exception has been thrown by the target of an invocation. (SQLEditors)
    ADDITIONAL INFORMATION:
    The 'DbProviderFactories' section can only appear once per config file. (System.Configuration)
    I was trying to design a table and it threw this exception.
    Exception has been thrown by the target of an invocation. (SQLEditors)
    ADDITIONAL INFORMATION:
    Unable to find the requested .Net Framework Data Provider.  It may not be installed. (System.Data)
    What am I missing? Do I need to download something?

    Hi Geoff33,
    According to the error messages, it might be caused by that there are duplicate <DbProviderFactories> tags in the machine.config files. As Satish’s post, please remove empty element DbProviderFactories in the following files.
    C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config
    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config
    However, if the error still occurs after that, it might be caused by that the SQL Server Management Studio (SSMS) is not installed properly. I recommend you to design the table via Transact-SQL. Alternatively, you can reinstall the client tools from installation
    media.
    Thanks,
    Lydia Zhang

Maybe you are looking for