Select from Function PIPELINED on PL/SQL Block

Hi folks,
I have a PL/SQL Block and I need this block to show me in a grid the rows from a variable table (Type table) that I have declared.
I don´t want to create Database objects, that's why I haven´t created tableTest like a type object in the database.
Example:
Declare
type tableTest is table of varchar2(500);
function test(indName IN VARCHAR2) return tableTest PIPELINED as
begin
pipe row (indName);
pipe row ('teste2');
return
end;
begin
-- HERE I NEED SHOW ROWS RETURNED BY FUNCTION WAS DECLARED;
-- Select * from TABLE(test('NAME'));
end;

You declare a pipelined table function by specifying the PIPELINED keyword. Pipelined functions can be defined at the schema level with CREATE FUNCTION or in a package. The PIPELINED keyword indicates that the function returns rows iteratively. The return type of the pipelined table function must be a supported collection type, such as a nested table or a varray. This collection type can be declared at the schema level or inside a package. Inside the function, you return individual elements of the collection type. The elements of the collection type must be supported SQL datatypes, such as NUMBER and VARCHAR2. PL/SQL datatypes, such as PLS_INTEGER and BOOLEAN, are not supported as collection elements in a pipelined function.
http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14261/tuning.htm

Similar Messages

  • Error while selecting  from nested table in PL/SQL block ............

    SQL> create type string_table is table of varchar(100);
    2 /
    Type created.
    declare
    v_names string_table := string_table();
    begin
    v_names.EXTEND(3);
    v_names(1) := 'name1';
    v_names(2) := 'name2';
    v_names(3) := 'name3';
    dbms_output.put_line(v_names(1));
    dbms_output.put_line(v_names(2));
    dbms_output.put_line(v_names(3));
    dbms_output.put_line(v_names.COUNT());
    select * from table(v_names);
    end;
    select * from table(v_names);
    ERROR at line 12:
    ORA-06550: line 12, column 7:
    PLS-00428: an INTO clause is expected in this SELECT statement

    select * from table(v_names);
    I guess ,here you were trying to put the content of the NT into another NT, or just trying to print it.
    But, I don't think INTO Clause is mandatory here.
    Please check your modified code (w/o INTO) and the output :
    DECLARE
       TYPE string_table IS TABLE OF VARCHAR (100);
       v_names   string_table := string_table ();
       v_test    string_table := string_table ();
    BEGIN
       v_names.EXTEND (3);
       v_names (1) := 'name1';
       v_names (2) := 'name2';
       v_names (3) := 'name3';
       DBMS_OUTPUT.put_line ('Old collection - '||v_names (1));
       DBMS_OUTPUT.put_line ('Old collection - '||v_names (2));
       DBMS_OUTPUT.put_line ('Old collection - '||v_names (3));
       DBMS_OUTPUT.put_line ('Old collection - '||v_names.COUNT ());
       DBMS_OUTPUT.put_line (CHR(10));
       /* SELECT * FROM TABLE (v_names); */
       v_test := v_names;
       DBMS_OUTPUT.put_line ('New collection -- '||v_test (1));
       DBMS_OUTPUT.put_line ('New collection -- '||v_test (2));
       DBMS_OUTPUT.put_line ('New collection -- '||v_test (3));
       DBMS_OUTPUT.put_line ('New collection -- '||v_test.COUNT ());
       DBMS_OUTPUT.put_line (CHR(10));
       /* Printing using FOR LOOP */
       FOR i IN v_test.FIRST..v_test.LAST
       LOOP
         DBMS_OUTPUT.put_line ('In FOR Loop --- '||v_test (i));
       END LOOP;
    EXCEPTION
       WHEN OTHERS
       THEN
          DBMS_OUTPUT.put_line ('Error ' ||SQLERRM|| DBMS_UTILITY.format_error_backtrace);
    END;gives o/p :
    Old collection - name1
    Old collection - name2
    Old collection - name3
    Old collection - 3
    New collection -- name1
    New collection -- name2
    New collection -- name3
    New collection -- 3
    In FOR Loop --- name1
    In FOR Loop --- name2
    In FOR Loop --- name3Refer this link -- http://docs.oracle.com/cd/E11882_01/appdev.112/e17126/tuning.htm#CIHGGBGF
    Edited by: ranit B on Dec 26, 2012 2:29 PM
    -- code modified
    Edited by: ranit B on Dec 26, 2012 2:45 PM
    -- code 'again' updated -- FOR LOOP added

  • Dynamic parameter selection from infoview not storing the sql password

    We are having the problem of dynamic parameter selection from infoview not storing the sql password as it does for the actual report. We are using Crystal Reports XI Release 2 version 11.5.3.438 (Not sure of SP level, asked in separate thread).
    To be more specific.
    We have created a report that dynamically populates the parameters of the report by pulling the records from the Informix sql database and allowing selection from there.
    In the Central Management Console for the report object we have set as follows:
    Process - Database:
    Use original database logon information from the report - the sql username and pw etc
    Use same database logon as when report is run
    Process - Parameters
    In selecting a default selection there is the option to put in the sql password, however, this does not stick and clears after update.
    As such the end result is that every time this report is run from infoview and a user chooses a parameter (there are 5), crystal goes through some timeout for about a minute or so and then requests the sql password, if a user then selects the next parameter, the same timeout and password dialog appears.
    We need the crystal report to handle to the sql password for fetching the parameters as well as for the database section of running the report, however, the parameters insists on the end user always putting the password in.
    This is 100% replicatable on our system.
    Any way that we can fix this?
    Will an update fix this issue? If so could you please advise which one?
    Thanks

    Hi,
    I am having the exact same problem. Any help?
    And what does "Use same database logon as when report is run" mean? For me that would be that no prompt is needed for getting values in a dynamic parameter...
    Regards
    Magnus

  • Select * from FUNCTION(a,b,c,...)

    Hi,
    Our client asked us not to use VIEW in our entire application!
    After wasting one week negotiating with them, I am looking for some alternatives for views to simplify our complex queries.
    Can I use functions instead of views in select statements? Could you give me a sample for SCOTT.EMP table? I am looking for something like:
    SELECT * FROM UDF_FUNCTION(123)
    Are functions a good alternative for views? What are my other options?
    Regards,
    Alan

    You can select from a function if you create a "pipelined function". I would definitely use a view if I could, since a pipelined function will almost certainly not perform as well as a well-tuned view. Pipelined functions can be useful for ETL transformations, but are probably not the best choice for data access routines to deliver results to an end-user.
    Anyway, here is a simple example, using the SCOTT sample schema:
    SQL> create type EmpType as object
      2  (
      3  empno number(4),
      4  ename varchar2(10),
      5  sal number(7,2)
      6  );
      7  /
    Type created
    SQL> create type EmpTabType as table of EmpType;
      2  /
    Type created
    SQL> create or replace function EmpFunc(p_in_sal IN NUMBER) return EmpTabType PIPELINED IS
      2    l_emp_rec EmpType := EmpType(NULL,NULL,NULL);
      3  begin
      4    for emp_rec in (select * from emp where sal > p_in_sal) loop
      5      l_emp_rec.empno := emp_rec.empno;
      6      l_emp_rec.ename := emp_rec.ename;
      7      l_emp_rec.sal := emp_rec.sal;
      8      PIPE ROW( l_emp_rec );
      9    end loop;
    10    return;
    11  end EmpFunc;
    12  /
    Function created
    SQL> select * from TABLE( EMPFUNC( 2000 ) );
         EMPNO ENAME             SAL
          7566 JONES            2975
          7698 BLAKE            2850
          7782 CLARK            2450
          7788 SCOTT            3000
          7839 KING             5000
          7902 FORD             3000
    6 rows selected
    SQL>

  • Why do i have to init a VARCHAR for a SELECT in a Pro*C PL/SQL block?

    Hi,
    i use PL/SQL Block in a Embedded C Programm and compile with the PRO*C Compiler. Oracle 10gR2.
    When i Select .. Into a VARCHAR bind variable, i have to initialize the variable before, otherwise i get an ORA-1458.
    Same problem with assignments to VARCHAR variables.
    Question: why do i need to initialize the variable?
    Tnx for your help!
    The following test program shows my issue:
    #include <stdio.h>
    #include <string.h>
    #include "oraca.h"
    #include "sqlca.h"
    #define USER "scott"
    #define PASSWORD "tiger"
    int main()
    EXEC SQL BEGIN DECLARE SECTION;
    char *db_user   = USER;
    char *db_passw  = PASSWORD;
    VARCHAR sysdate_str[64];
    EXEC SQL END DECLARE SECTION;
    EXEC SQL CONNECT :db_user identified by :db_passw;
    /* this works */
    sysdate_str.len = 1000; /* invalid length */
    EXEC SQL SELECT
    to_char( sysdate, 'dd.mm.yy hh24:mi:ss' )
    into :sysdate_str
    from DUAL
    printf ("sqlca.sqlcode %d\n", sqlca.sqlcode);
    /* following code does not work, sqlcode = - 1458 */
    /* 01458, 00000, "invalid length inside variable character string" */
    sysdate_str.len = 1000; /* invalid length */
    EXEC SQL EXECUTE
    BEGIN
    select to_char( SYSDATE, 'dd.mm.yy hh24:mi:ss')
    into :sysdate_str
    from dual;
    END;
    END-EXEC;
    printf ("sqlca.sqlcode %d\n", sqlca.sqlcode);
    /* following code does not work, sqlcode = - 1458 */
    /* 01458, 00000, "invalid length inside variable character string" */
    sysdate_str.len = 1000; /* invalid length */
    EXEC SQL EXECUTE
    BEGIN
    :sysdate_str := to_char( SYSDATE, 'dd.mm.yy hh24:mi:ss');
    END;
    END-EXEC;
    printf ("sqlca.sqlcode %d\n", sqlca.sqlcode);
    return(0);
    Edited by: jjaeckel on May 5, 2010 8:37 PM

    jjaeckel wrote:
    When i Select .. Into a VARCHAR bind variable, i have to initialize the variable before, otherwise i get an ORA-1458.A bind variable in a SQL is simply a place holder. The SQL engine has no idea what data type the value for that placeholder will be. When itself needs to return a value via that placeholder to the caller, it needs to know what the limits/size of the caller's variable is that will be receiving the value from it.
    The way that the SQL engine knows what the data type and size are of a placeholder/bindvar, is by you the caller, telling it.. by binding the variable you will be using, to this placeholder.
    This bind process "exposes" the data type and size of the variable that will be used for binding (sending/receiving data).

  • Group By function inside a PL/sql Block

    Hi,
    I have a select statement which looks like this -
    select Region, count(region) from QUOTE_LETTERS_MASTER where version != 'v112012' and source = 'http://esource.oraclecorp.com/portal/pls/portal/esrc.esr_portlet.show?id=74,34,12202' and region != 'eSource'
    group by region
    REGION     COUNT(REGION)
    EMEA      25
    NA     1
    LAD     10
    Japan 1
    Now the above code will have different result based on the version and source provided.
    I want to use a code on similar lines where the based on version and source which will come from a cursor, i want the region and count of region, but because the result will keep on changing based on the where clause i am not sure how to use the similar code as above inside a pl/sql block.
    Thank you,
    rakesh

    Hi, I haven't tested this but how about something like this:
    create or replace procedure testproc(p_version VARCHAR2, p_source VARCHAR2)
    as
    v_version varchar2(100);
    v_source varchar2(1000);
    cursor c1 is
    select Region, count(region) as cnt
    from QUOTE_LETTERS_MASTER
    where version != v_version
    and source = v_source
    and region != 'eSource'
    group by region;
    begin
    v_version := p_version;
    v_sourse := p_source;
    for r1 in c1 loop
       dbms_output.put_line(r1.region||' '||r1.cnt);
    end loop;
    end;

  • Obtaining a collection as a return from an execute immediate pl/sql block

    version 10.2
    I need to obtain the collection back from the execute immediate of a pl/sql block:
    procedure block(owner varchar2) is
    stmt                   long;
    objecttab_coll         dbms_stats.objecttab;
    begin
    stmt := '
       begin
        dbms_stats.gather_schema_stats(''' || owner || '''
         ,options => ''LIST AUTO''
         ,objlist => :objecttab_coll
       end;'; 
    execute immediate stmt returning into objecttab_coll;
    -- do more stuff here
    end block;I have tried this + a few variations but with no luck. In looking through the docs I do not see an example. can this be done?
    Thanks
    Ox

    I dont find any need for an execute immediate here. This must be just enough.
    procedure block(owner varchar2)
    is
         objecttab_coll         dbms_stats.objecttab;
    begin
         dbms_stats.gather_schema_stats(ownname => owner, options => 'LIST AUTO', objlist => objecttab_coll);
         -- do more stuff here
    end block;Thanks,
    Karthick.

  • Select from sys.all_ind_columns works in sql*plus but not in stored proc

    I'm writing a query to find duplicate rows in a temporary table which has no unique index defined before I insert the data into the real table. I'm trying to query the sys.all_ind_columns view for the target table which belongs to a different schema:
    SELECT column_name colnm
    FROM sys.all_ind_columns i
    WHERE i.table_owner = 'SUSDB'
    AND i.index_name LIKE '%LUK'
    AND i.table_name = &tbnm
    ORDER BY i.column_position;
    This works from my GUI interface and returns five rows but when I put it into a stored procedure I get now data returned. I have granted my userid SELECT ANY DICTIONARY authority. What else do I need?

    CREATE OR REPLACE FUNCTION bog_elsa2_leslie.diag_msg_1000_cursor(i_rept_inst IN VARCHAR2,
    i_rept_time_frame IN VARCHAR2,
    i_table_name IN VARCHAR2,
    i_column_name IN VARCHAR2,
    i_domain_table IN VARCHAR2,
    i_domain_column IN VARCHAR2,
    i_domain_code IN VARCHAR2,
    i_trace_flg IN NUMBER := 0)
    RETURN VARCHAR2 IS
    cursor_stg VARCHAR2(4000);
    || File name: diag_msg_1000_cursor.fnc
    || Created by: ELSA.LESLIE
    || Created on: 20071215 4:08:20 AM
    || Purpose: Build the string that will retrieve PRIKEY and CONTENTS
    || from the target table, university, time frame, submission
    || and table passed as parameters for the 1000 dignostic.
    || Diagnostic 1000:
    || Validate that the table's logical unique key constraint
    || is not violated.
    || In: ***
    || *** ALL INPUT VARIABLES MUST BE DECLARED EVEN IF THEY ARE
    || *** NOT USED IN THIS PARTICULAR FUNCTION BECAUSE THE
    || *** EDIT_ANY_TABLE PROCEDURE CALLS THE FUNCTION IN AN
    || *** EXECUTE IMMEDIATE STATEMENT THAT REQUIRES THE 'USING'
    || *** PHRASE BE PART OF THE CALLING PROGRAM RATHER THAN BEING
    || *** INCLUDED IN THE RETURNED CURSOR_STG.
    || ***
    || i_rept_inst = reporting institution (eg. UF, FSU)
    || i_rept_time_frame = reporting time frame (eg., 200608, 20062007)
    || i_table_name = target table to be edited (eg. BUILDINGS, ENROLLMENTS)
    || i_trace_flg is optional and is used for debugging (values: TRUE/FALSE)
    || [not used] i_column_name = eg. ALTER_YR, BASE_YR
    || [not used] i_domain_table = the name of the domain table containing valid values
    || [not used] (eg. DOMAIN_MAIN_VALUES, DOMAIN_UNIV)
    || [not used] i_domain_column = the name of the column in the domain table that
    || [not used] contains the valid values (eg. CODE, OPEID_CD)
    || [not used] i_domain_code = the 5-digit domain code (eg. 10021, 01045)
    || Out: cursor_stg = executable SQL to return error row information
    || Dependencies: Logical Unique Key for tables must be have the string 'LUK'
    || postpended to it's name.
    || Exceptions: none
    || Copyright: BOG 2007
    || ***************************************************
    || Modifications:
    || Userid - Date - Modification description
    -- Constants and special assignments
    rept_inst VARCHAR2(4) := upper(i_rept_inst);
    rept_time_frame VARCHAR2(8) := i_rept_time_frame;
    table_name VARCHAR2(30) := upper(i_table_name);
    column_name VARCHAR2(30) := upper(i_column_name);
    domain_table VARCHAR2(30) := upper(i_domain_table);
    domain_column VARCHAR2(30) := upper(i_domain_column);
    domain_code VARCHAR2(5) := upper(i_domain_code);
    trace_flg NUMBER := i_trace_flg;
    file_name VARCHAR2(100) := 'diag_msg_1000_cursor: ';
    unq_cols VARCHAR2(1000) := NULL;
    unq_contents VARCHAR2(4000) := NULL;
    unq_where VARCHAR2(4000) := NULL;
    -- Accounting of process n/a all contained in the for loop
    row_num NUMBER := 0;
    -- Object types - n/a
    -- Cursors
    CURSOR ix_cols_curr(tbnm VARCHAR2 := table_name) IS
    SELECT column_name colnm
    FROM sys.all_ind_columns i
    WHERE i.table_owner = 'SUSDB'
    AND i.index_name LIKE '%LUK'
    AND i.table_name = tbnm
    ORDER BY i.column_position;
    -- Cursor variables n/a
    -- errors and exceptions
    sql_code NUMBER;
    sql_errm VARCHAR2(255);
    BEGIN
    -- output trace information if requested
    IF trace_flg = 1
    THEN
    dbms_output.put_line(file_name || 'rept_inst = ' || rept_inst);
    dbms_output.put_line(file_name || 'rept_time_frame = ' || rept_time_frame);
    dbms_output.put_line(file_name || 'table_name = ' || table_name);
    dbms_output.put_line(file_name || 'column_name = ' || column_name);
    dbms_output.put_line(file_name || 'domain_table = ' || domain_table);
    dbms_output.put_line(file_name || 'domain_column = ' || domain_column);
    dbms_output.put_line(file_name || 'domain_code = ' || domain_code);
    END IF;
    -- ix_cols_loop builds a string of the columns contain in the
    -- logical unique key which is then later incorporated into the
    -- select cursor returned to the calling program.
    FOR this_col IN ix_cols_curr(table_name)
    LOOP
    <<ix_cols_loop>>
    -- output trace information if requested
    IF trace_flg = 1
    THEN
    row_num := ix_cols_curr%ROWCOUNT;
    dbms_output.put_line(file_name || 'row=' || row_num ||
    'column_name=' || this_col.colnm);
    END IF;
    IF unq_cols IS NOT NULL
    THEN
    unq_cols := unq_cols || ', ';
    unq_contents := unq_contents || ', ';
    END IF;
    unq_cols := unq_cols || this_col.colnm;
    unq_contents := unq_contents || q'[']' || this_col.colnm ||
    q'['=]' || this_col.colnm;
    unq_where := unq_where || 'AND tbl.' || this_col.colnm ||
    ' = dups.' || this_col.colnm;
    END LOOP ix_cols_loop;
    IF trace_flg = 1
    THEN
    dbms_output.put_line(file_name || 'unq_cols =' || unq_cols);
    dbms_output.put_line(file_name || 'unq_contents =' || unq_contents);
    dbms_output.put_line(file_name || 'unq_where =' || unq_where);
    END IF;
    cursor_stg := 'SELECT prikey, ' || unq_contents || ' AS contents ' ||
    'FROM univdb.' || table_name || ' tbl, (SELECT ' ||
    unq_cols || ', COUNT(*) FROM univdb.' || table_name ||
    q'[ WHERE rept_inst = ']' || rept_inst || q'[']' ||
    q'[AND rept_time_frame = ']' || rept_time_frame || q'[']' ||
    ' GROUP BY ' || unq_cols || ' HAVING COUNT(*) > 1) dups' ||
    q'[ WHERE tbl.rept_inst = ']' || rept_inst || q'[']' ||
    q'[ AND tbl.rept_time_frame = ']' || rept_time_frame ||
    q'[']' || unq_where;
    -- output trace information if requested
    IF trace_flg = 1
    THEN
    dbms_output.put_line(file_name || 'cursor_stg = ' || cursor_stg);
    END IF;
    RETURN(cursor_stg);
    EXCEPTION
    -- block exception
    WHEN OTHERS THEN
    sql_code := SQLCODE;
    sql_errm := SQLERRM;
    IF trace_flg = 1
    THEN
    dbms_output.put_line(file_name || ' ROW NUM ' || row_num || ' sql code ' ||
    sql_code || ' sql message ' || sql_errm);
    END IF;
    END diag_msg_1000_cursor;

  • Select from function with named parameters doesn't work

    Hello,
    I'm trying to execute the next sql statement:
    SELECT mypack.getvalue(user_id => 231, status => 'closed') AS someAlias FROM DUAL;
    I'm getting the next Error:
    Error: ORA-00907: missing right parenthesis
    But the next works fine:
    SELECT mypack.getvalue(231,'closed') AS someAlias FROM DUAL;
    What I'm doing wrong?
    Is there a way to call a Function and return it's result as a single-row query?
    Thanks for any suggestions.

    Thanks for your answers.
    Just want to explain what I want to accomplish:
    I want to create PL/SQL statement which:
    1) Calls Function in named notation way;
    2) Returns a query which contains a single row - a Function result.
    I know in Transact-SQL I can accomplish this the next way:
    DECLARE @return_value INT
    EXEC[myproc]
    @id=2,
    @status='ok',
    @ret_param=@return_value OUTPUT
    SELECT @return_value AS my_return_value
    The last SELECT call returns a query with one row in it.
    How can I do the same in Oracle?
    Thanks a lot!

  • Select from function return rowtype @ db link

    Hi, I am trying to select a row from a function which return a row type @ another DB.
    First DB
    ==========
    Function: fn_something(params) return mytable@snddb%rowtype
    DB Link: snddb
    Second DB
    ==========
    Table: mytable (Column: mycol)
    I have tried to execute query
    select fn_something(params) from dual
    OR
    select mycol from table(fn_something(params))
    but I have got "invalid datatype" error.
    What would be the correct syntax for my query? Thanks.

    Hi Andy,
    Thanks for your reply.
    My function itself has no problem and has been using for a while.
    The function return a rowtype(a table row) and it is using in a stored procedure.
    It could be done in stored procedure but I would like to know if I could call it directly from a query.
    I have just read another thread
    Help - Oracle function w/RETURN VIEW_NAME%ROWTYPE
    which is quite similar to mine
    but I am trying to get a column value from the function and execute an insert statement.
    Could I do it without wrapped by begin end ?

  • Error while executing SQL query -' Must Specify Table to select from'

    Hi all,
    While executing query using query generator
    it shows error message
    [Microsoft][SQL Native Client][SQL Server]Must specify table to select from.
    2). [Microsoft][SQL Nativ
    SELECT T1.ItemCode, T1.Dscription AS 'Item Description', T1.Quantity, T1.Price, T1.LineTotal,
    (Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=-90 AND T1.LineNum=T2.LineNum) as 'BEDAmt',
    (Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=-60 AND T1.LineNum=T2.LineNum) as 'ECSAmt',
    (Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=7 AND T1.LineNum=T2.LineNum) as 'HECSAmt',
    (Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=1 AND T1.LineNum=T2.LineNum) as 'VATAmt',
    (Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=4 AND T1.LineNum=T2.LineNum) as 'CSTAmt'
    FROM dbo.[OPCH] T0  INNER JOIN PCH1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN PCH4 T2 ON T2.DocEntry=T0.DocEntry
    WHERE T0.DocDate >='[%0]' AND  T0.DocDate <='[%1]' AND T0.DocType = 'I'
    GROUP BY T1.ItemCode,T1.Dscription,T1.Quantity, T1.Price, T1.LineTotal,T0.DocEntry,T1.DocEntry,T1.LineNum,T2.LineNum
    It's executing fine in MS SQL Server Studio Management.
    Please give y'r ideas to solve the problem.
    Jeyakanthan

    try this, it works fine in my B1:
    SELECT T1.ItemCode, T1.Dscription AS 'Item Description', T1.Quantity, T1.Price, T1.LineTotal,
    (Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=-90 AND T1.LineNum=T2.LineNum) as 'BEDAmt',
    (Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=-60 AND T1.LineNum=T2.LineNum) as 'ECSAmt',
    (Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=7 AND T1.LineNum=T2.LineNum) as 'HECSAmt',
    (Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=1 AND T1.LineNum=T2.LineNum) as 'VATAmt',
    (Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=4 AND T1.LineNum=T2.LineNum) as 'CSTAmt'
    FROM dbo.OPCH T0  INNER JOIN PCH1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN PCH4 T2 ON T2.DocEntry=T0.DocEntry
    WHERE T0.DocDate >='[%0]' AND  T0.DocDate <='[%1]' AND T0.DocType = 'I'
    GROUP BY T1.ItemCode,T1.Dscription,T1.Quantity, T1.Price, T1.LineTotal,T0.DocEntry,T1.DocEntry,T1.LineNum,T2.LineNum
    B1 don't like brackets!
    Regards

  • Is select from view faster then select from table..???

    Hello Gurus,
    I want to query some data from two tables, both of table have many columns (attributes) and many rows...
    I use several where clauses to retrieve data from those tables..
    witch one is faster, I create a view or I just "select" from those tables???
    Regards.
    Nia...

    riedelme wrote:
    3360 wrote:
    riedelme wrote:
    Selecting through a view almost never helps performance and frequently hurts.Views do not affect performance.
    Views are simply queries and like queries there are fast and slow ones.I disagree.
    First of all, to use a view you are executing a query to get a result set, then accessing the data from that result set - a built-in extra step to perform to get data.First of all that entire explanation of how views work is not correct. The optimizer will rewrite the query to make the view go away if possible.
    SQL> create or replace view v as select * from dual;
    View created.
    SQL> explain plan for select * from dual where dummy = 'X';
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 272002086
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |     1 |     2 |     2   (0)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| DUAL |     1 |     2 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("DUMMY"='X')
    13 rows selected.
    SQL> explain plan for select * from v where dummy = 'X';
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 272002086
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |     1 |     2 |     2   (0)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| DUAL |     1 |     2 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("DUMMY"='X')
    13 rows selected.Exactly the same.
    >
    Second, when accessing the data from the view the result sets don't have indexes for fast lookups and efficient joins on later steps.This is also known as just making stuff up and is not how the database works. care to share any references at all for any of this?
    >
    Third, the systems I've seen that use views extensively - I am looking at one now - tend to perform joins on views using the same tables with the same data over and over. This is a design issue and not specifically a problem with views but they lend themselves to this misuse much too easilyCorrect as I said a view is just a query, and just like queries there are good fast views and bad slow views
    >
    I'll concede that the problem is not specifically with views themselves but as I just said they lend themselves to misuse. Tuning views of views and views joined to views is difficultYes, queries can be misused as can almost all SQL functions and functionality.
    As I said - Views are simply queries and like queries there are fast and slow ones.
    Nothing that you have posted that is accurate changes that.

  • Must specify table to select from

    hi everybody
    i think  sometime we received this error message:
    1).[Microsoft][SQL Server Native Client 10.0][SQL Server]Must specify table to selet from. 2).[Microsoft][SQL Server Native Client 10.0][SQL Server]Statment 'Contrato de Servicio' (OCTR)(s) could not be prepared.
    when i'm working in SQL Server the qry run fine, but when i run in SAP, i receive the error before mentioned.
    the Qry is this:
    DECLARE @FechaIni datetime,     
            @FechaFin datetime,
            @FechaAct datetime
    SET @FechaAct = GETDATE()
    SET @FechaIni = [%0]
    SET @FechaFin = [%1]
    CREATE TABLE #Libo_Mayor_CS (
                                    CodCta nvarchar(max),
                                    CtasPadre nvarchar(max),
                                    NbreCta nvarchar(max),
                                    Nivel numeric(1),
                                    Rubro numeric(1),
                                    SldoInicial numeric(19,6),
                                    Debe numeric(19,6),
                                    Haber numeric(19,6),
                                    SldoFinal numeric(19,6)
    INSERT INTO #Libo_Mayor_CS
    SELECT T0.[AcctCode],
           CASE
               WHEN T0.[Levels] <=3 THEN T0.[AcctName]
               ELSE  ''
           END,
           T0.[Levels],
           T0.[GroupMask],
           0.00,
           0.00,
           0.00,
           0.00                                          
    FROM OACT T0
         LEFT JOIN JDT1 T1 ON T0.[AcctCode] = T1.[Account]
    WHERE T0.[Levels] BETWEEN 1 AND 3 AND
          T0.[GroupMask]   BETWEEN 1 AND 5
    GROUP BY T0.[AcctCode],
             T1.[Account],
             T0.[Levels],
             T0.[AcctName],
             T0.[GroupMask]
    INSERT INTO #Libo_Mayor_CS
    SELECT T0.[AcctCode],
           CASE
               WHEN T0.[Levels] >3 THEN T0.[AcctName]
               ELSE  ''
           END,
           T0.[Levels],
           T0.[GroupMask],
           CASE
               WHEN T0.GroupMask  = 1 THEN (select t11.[CurrTotal]+sum(t10.[Debit])-sum(t10.[credit]) from oact t11 left join jdt1 t10 on t11.[AcctCode] = t10.[Account] where t10.[RefDate] between @FechaIni and @FechaAct and t11.[AcctCode] = T0.[AcctCode] group by t11.[CurrTotal])
               WHEN T0.GroupMask  = 2 THEN (select t11.[CurrTotal]-sum(t10.[Credit])-sum(t10.[Debit]) from oact t11 left join jdt1 t10 on t11.[AcctCode] = t10.[Account] where t10.[RefDate] between @FechaIni and @FechaAct and t11.[AcctCode] = T0.[AcctCode] group by t11.[CurrTotal])
               WHEN T0.GroupMask  = 4 THEN (select t11.[CurrTotal]+sum(t10.[Debit])-sum(t10.[credit]) from oact t11 left join jdt1 t10 on t11.[AcctCode] = t10.[Account] where t10.[RefDate] between @FechaIni and @FechaAct and t11.[AcctCode] = T0.[AcctCode] group by t11.[CurrTotal])
               WHEN T0.GroupMask  = 5 THEN (select t11.[CurrTotal]-sum(t10.[Credit])-sum(t10.[Debit]) from oact t11 left join jdt1 t10 on t11.[AcctCode] = t10.[Account] where t10.[RefDate] between @FechaIni and @FechaAct and t11.[AcctCode] = T0.[AcctCode] group by t11.[CurrTotal])
           END,
           SUM(T1.[Credit]),
           SUM(T1.[Debit]),
           0.00                                          
    FROM OACT T0
         LEFT JOIN JDT1 T1 ON T0.[AcctCode]  = T1.[Account]
    WHERE T0.[Levels] > 3 AND
          T0.[GroupMask]  BETWEEN 1 AND 5 AND
         (T1.[RefDate] between @FechaIni AND @FechaFin)
    GROUP BY T0.[AcctCode],
             T1.[Account],
             T0.[Levels],
             T0.[AcctName],
             T0.[GroupMask]
    SELECT A.[CodCta] 'Codigo de Cuenta',
           A.[CtasPadre] 'Cuentas Padre',
           A.[NbreCta] 'Nombre de Cuenta',
           A.[Nivel] 'Nivel',
           A.[Rubro] 'Rubro',
           A.[SldoInicial] 'Saldo Inicial',
           A.[Debe] 'Debito',
           A.[Haber] 'Credito',
           CASE
               WHEN A.[Rubro] = 1 THEN (A.[SldoInicial] + A.[Debe] - A.[Haber])
               WHEN A.[Rubro] = 2 THEN (A.[SldoInicial] + A.[Haber] - A.[Debe])
               WHEN A.[Rubro] = 4 THEN (A.[SldoInicial] + A.[Debe] - A.[Haber])
               WHEN A.[Rubro] = 5 THEN (A.[SldoInicial] + A.[Haber] - A.[Debe])
               ELSE 0
           END 'Saldo'
    FROM #Libo_Mayor_CS A
    ORDER BY A.[CodCta]
    DROP TABLE #Libo_Mayor_CS
    if  assign the value to variables directly the Qry run in SAP but when i change the comodin to capture the variables value of SAP , there is when the problem ocurre
    DECLARE @FechaIni datetime,     
                    @FechaFin datetime,
                    @FechaAct datetime
    SET @FechaAct = GETDATE()
    SET @FechaIni =  '20110601'
    SET @FechaFin = '20110630'
    i wait for your recomendations
    Edited by: AlexMeza on Jun 15, 2011 1:29 AM

    Hi all !
    Sorry because i dont know where post new.
    My issue, when i using querry manager to call store in Database like this
    Declare @Fromdate Datetime
    Declare @Todate Datetime
    Declare @AcctCode nvarchar (20)
    set @Fromdate = (select distinct (T1.RefDate) from OJDT T1 where T1.RefDate = '[%0]')
    set @Todate = (select distinct (T2.RefDate) from OJDT T2 where T2.RefDate = '[%1]')
    set @AcctCode = (select distinct(T3.AcctCode) from OACT as T3 where T3.AcctCode ='[%2]' )
    exec [USP_RPT_FI_GENERALLEDGER] @Fromdate, @Todate, @AcctCode
    and i run this querry
    this error:
    1). [Microsoft][SQL Server Native Client 10.0][SQL Server]Must specify table to select from. 2). [Microsoft][SQL Server Native Client 10.0][SQL Server]Statement 'Service Contracts' (OCTR) (s) could not be prepared.
    Please help me fix this issue
    Regards!
    John Le.

  • Pipelined function, select from table t1 or t2 depending on user's choise

    Hi all,
    My need is to select data from table t1 or t2 depending on user's choise using pipelined function. You can find my first guess below. Maybe someone can help me to save some code, I mean getting the same result without writing "PIPE ROW" twice.
    FUNCTION fn_indicators (p_datbeg date, p_datend date, p_indicatorid number) return cl_risk_act pipelined IS
    v_obj cl_user_type;
    BEGIN
    case when p_indicatorid = 1 then
    FOR e IN (
    select trunc(sysdate-1) as adate, 0 as cid, 0 as indicatorid, '0' as code, '0' as indicatorname, 0 as value, 0 as cnt, '0' as cname from dual
    LOOP
    v_obj.adate              := e.adate;
    v_obj.cid                  := e.cid;
    v_obj.indicatorid       := e.indicatorid;
    v_obj.code               := e.code;
    v_obj.indicatorname  := e.indicatorname;
    v_obj.value              := e.value;
    v_obj.cnt                 := e.cnt;
    v_obj.cname            := e.cname;
    PIPE ROW (v_obj);
    END LOOP;
    when p_indicatorid = 2 then
    FOR e IN (
    select trunc(sysdate-2) as adate, 1 as cid, 1 as indicatorid, '1' as code, '1' as indicatorname, 1 as value, 1 as cnt, '1' as cname from dual
    LOOP
    v_obj.adate              := e.adate;
    v_obj.cid                  := e.cid;
    v_obj.indicatorid       := e.indicatorid;
    v_obj.code               := e.code;
    v_obj.indicatorname  := e.indicatorname;
    v_obj.value              := e.value;
    v_obj.cnt                 := e.cnt;
    v_obj.cname            := e.cname;
    PIPE ROW (v_obj);
    END LOOP;
    end case;
    RETURN;
    end;

    marco wrote:
    Justin,
    In my real code table real_t1 or pipelinedfn_t2 is joined to other tables, so surely real code is bigger than sample one. It is not wise to keep code twise with only one table name changed. I think about dynamic sql to choose from two tables:
    with t1 as
    (select * from real_t1
    t2 as
    (select * from pipelinedfn_t2
    t3 as (
    [dynamic selection of t1 or t2 depending on user's choise]
    select * from t3, t... where...I don't know correct syntax.
    Any ideas?
    >Justin,
    In my real code table real_t1 or pipelinedfn_t2 is joined to other tables, so surely real code is bigger than sample one. It is not wise to keep code twise with only one table name changed. I think about dynamic sql to choose from two tables:
    with t1 as
    (select * from real_t1
    t2 as
    (select * from pipelinedfn_t2
    t3 as (
    [dynamic selection of t1 or t2 depending on user's choise]
    select * from t3, t... where...I don't know correct syntax.
    Any ideas?
    Dynamic code does NOT scale.
    Making the tradeoff of smaller code size for reduced performance is not one that I would make.

  • Resolved: Use value from select list in pl/sql block

    Hello,
    I have a form with a select list: P18_BONUSTYPE, the values of which come from a LOV.
    When the user clicks a button, a page process is used to insert a row into a table.
    When I use the :P18_BONUSTYPE bind variable in my insert statement I get an error "Invalid number" I get an "Invalid number" error. I assume that APEX is using the displayed text in that bind variable, not its actual (html option) value.
    I checked the HTML of the page, and the correct values are in the select list.
    Can someone tell me how to get the value into a bind variable that can be used in a pl/sql block for a page process?
    Thanks
    Message was edited by:
    Neeko
    Issue was a value in another item.

    Did you tried changing the value using "to_number"? (i.e. to_number(:P18_BONUSTYPE)).
    Max.

Maybe you are looking for

  • Extension for creating a zip file and unzipping it

    Iam totally new to Dreamweaver and the extensions. So please help me with this. Assuming i have a .zip file and it contains some html pages along with css and gifs. The req is to have an Import option, which given this zip file, can unzip its content

  • Apple: When will it be possible to use Airport Express to stream images (from program/video/photo) from my IMAC to my TV?

    Would like so see a future when I don't have to plug in my laptop to my TV every time I want to se a picture !! My IMac is my mainframe the laptop is a smartdrive with a screen :-)

  • Hreff works in IE but not in Firefox

    in my html code I am using css and absolute positiioning. I just added 4 new items and they do not show the 'hand' when mouse is over them. In IE they are OK I can give you the address of the page so you can see the problem better thank

  • First GarageBand import: resounding silence

    Torally wet-behind-the-ears Logic Pro 9 nooobie here. Wanted to move to Logic because GB keeps unpredictably and silently wiping real instrument files in the .band package. I'm sick of it and nobody on GB forums can explain why it happens or how to p

  • What are the properties of 0Material ?

    What are the properties of 0Material. Where to look for information before installing it through bi content. Why we use it , we could have taken one new infoobject and used it. Thanks Edited by: PRASHANT SINGHAL on May 12, 2008 8:48 AM