A SELECT into a procedure

Hello,Can I show the result of a SELECT .. FROM.. WHERE.. into a procedure?
For example:
CREATE OR REPLACE PROCEDURE nuova_ricerca (p_Stringa VARCHAR2)
AS
BEGIN
SELECT *
FROM ArchivioSoluzioni
WHERE Problema LIKE ConvertiPerLike(p_Stringa);
END;
why I can use
SELECT * INTO DUMMYArchivioSoluzione.Camp1, DUMMYArchivioSoluzione.Camp2..
If the result of my SELECT is constructed by 2 rows?
p.s
ConvertiPerLike is a simple function.
excuse for my bad english

Do not copy the record Operatore in emprec...Why?Because
SELECT * INTO emprec
FROM Operatore;
potentially returns MANY records (see my above post). If you want
to get the result you have to restrict the selection with WHERE caluse
which gaurantees you select ONE row, NOT MANY.
If you want to select many rows you have to think of the collection
and BULK COLLECT INTO statement:
SQL> create or replace procedure foo
  2  is
  3   type t1 is table of emp%rowtype index by pls_integer;
  4   t t1;
  5  begin
  6   select * bulk collect into t from emp;
  7  end;
  8  /
Procedure created.
SQL> exec foo;
PL/SQL procedure successfully completed.or to think of the cursor using as it was pointed out above:
SQL>/* Just for illustration */
SQL> create or replace procedure foo
  2  is
  3   erc emp%rowtype;
  4  begin
  5   for v in (select * from emp) loop
  6    erc := v;
  7   end loop;
  8  end;
  9  /
Procedure created.
SQL> exec foo;
PL/SQL procedure successfully completed.Rgds.

Similar Messages

  • How to modify a Procedure "select into" statement to use a cursor

    The below code fails with exception too many rows. How do I modify the Procedure's Select Into statement to use a cursor?
    CREATE OR REPLACE PROCEDURE Track_Asset(
       business_date IN NUMBER DEFAULT NULL,
       missing_table_name  OUT VARCHAR2)
    IS
       ln_business_date NUMBER;
        incorrectdateformat EXCEPTION;
    BEGIN
       IF business_date < 0
       THEN
          RAISE incorrectdateformat;
       ELSE
          DECLARE
            ln_business_date NUMBER;
          BEGIN
             SELECT MAX(business_date)
             INTO ln_business_date
             FROM sproof ;
          EXCEPTION
            WHEN NO_DATA_FOUND THEN
             dbms_output.put_line('NO MATCH FOUND');
            WHEN OTHERS THEN
            dbms_output.put_line('ORACLE ERROR :' || SQLERRM);       
          END;
          DECLARE
            missedfeedfnd EXCEPTION;
          BEGIN
             SELECT 'Missing Value : ' || table_name
             INTO missing_table_name
             FROM (
                SELECT UPPER(table_name) table_name
                FROM filespec
                WHERE data_table_name IN ('TABLE1','TABLE2','TABLE3')
                MINUS (
                SELECT DISTINCT UPPER(first_table_name)
                FROM dpca
                WHERE business_date = ln_business_date
                AND first_table_name IN ('TABLE1','TABLE2','TABLE3')
                GROUP BY UPPER(first_table_name) UNION
                SELECT UPPER(first_table_name)
                FROM dpca
                WHERE business_dt_num = TO_NUMBER( SUBSTR('201111', 1, 6) || '01' )
                AND first_table_name = 'TABLE4'
                GROUP BY UPPER(first_table_name) ));
                IF missing_table_name  IS NOT NULL THEN
                   dbms_output.put_line('Missing Value : '|| missing_table_name);
                   RAISE missedfeedfnd;
                ELSE
                  NULL;
                END IF;
          EXCEPTION
             WHEN TOO_MANY_ROWS THEN
       DBMS_OUTPUT.PUT_LINE (' SELECT INTO statement retrieved multiple rows');
              WHEN missedfeedfnd THEN
              raise_application_error ( - 20003, 'Missed Feed');
          END;
        END IF;
          EXCEPTION
       WHEN incorrectdatevalue
       THEN
          raise_application_error ( - 20001, 'Incorrect/Bad Date Entered');
    END;

    ok try this - OUT param will be populated with comma separated list of table names:
    PROCEDURE Track_Asset(
       business_date IN NUMBER DEFAULT NULL,
       missing_table_name  OUT VARCHAR2)
    cursor c_table_names is
    select datatablename
    from   ( select upper(datatablename) datatablename
             from   filespec
             where  data_table_name in ('TABLE1','TABLE2','TABLE3'                                 )
            MINUS
            ( select upper(first_table_name)
              from   dpca
              where  business_dt_num = [-- this date is retrieved by getting the MAX(business_date) from sproof table]
                     and fus_data_table_name in ('TABLE1','TABLE2','TABLE3'
              group  by
                     upper(first_table_name)
             UNION
              select upper(first_table_name)
              from   dpca
              where  business_dt_num = to_number( substr('201111',1,6) || '01' )
                     and first_table_name = 'TABLE4'
              group  by
                     upper(first_table_name)
    begin
       for rec in c_table_names
       loop
           missing_table_name  := missing_table_name  || rec.datatablename ||',';
       end loop;
       missing_table_name  := rtim(missing_table_name , ',');
    end ;HTH
    Edited by: user130038 on Dec 28, 2011 8:46 AM

  • Passing a table into a procedure to be used in a curor

    Hi,
    I'm using Oracle 9.2.0.6
    I have a procedure that searches all objects for a passed in string value. The procedure is below.
    CREATE OR REPLACE PROCEDURE Find_String (
    pin_referenced_name IN dba_dependencies.referenced_name%TYPE)
    IS
    cursor cur_get_dependancy
    is
    SELECT distinct owner, name, type
      FROM [email protected]
    WHERE lower(referenced_name) = lower(pin_referenced_name) --'ftbv_salesrep_all_1d'
       AND referenced_type != 'SYNONYM'
    order by name;
    v_owner  varchar2(40);
    v_name   varchar2(50);
    v_type   varchar2(40);
        BEGIN
           dbms_output.put_line(upper(pin_referenced_name)||' is found in the following objects.');
           dbms_output.put_line(' ');
           dbms_output.put_line(RPAD('OWNER', 30, ' ')||RPAD('NAME', 60, ' ')||RPAD('OBJECT TYPE', 30, ' '));
           dbms_output.put_line('-------------------------------------------------------------------------------------------------------------------');
            FOR i IN cur_get_dependancy
            LOOP
                v_owner := RPAD(i.owner, 30, ' ');
                v_name  := RPAD(i.name, 45, ' ');
                v_type  := RPAD(i.type, 30, ' ');
                dbms_output.put_line(v_owner ||v_name|| v_type);
            END LOOP;
    END find_string;I was wondering if there's any way I could pass in the table name, and the name of the DB link to be used in the cursor, into the procedure and rig the cursor to be able to accept that as a parameter. I want our users to be able to search different databases using this utility code.
    I thought of NDS, and that would be a way to do it, however I'm not sure if I could use an NDS statement in conjunction with a cursor.
    Does anybody have any suggestions?
    Thanks

    One approach (there are obviously many ways to skin this particular cat)
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    c1           sys_refcursor;
      3    l_val        number;
      4    l_table_name varchar2(30) := 'dual';
      5  begin
      6    open c1 for 'select 1 from ' || l_table_name;
      7    loop
      8      fetch c1 into l_val;
      9      exit when c1%notfound;
    10      dbms_output.put_line( l_val );
    11    end loop;
    12    close c1;
    13* end;
    SQL> /
    1
    PL/SQL procedure successfully completed.Justin

  • Select Into statement in db function - query from granted schema table

    problem with "select into" in db function in 10.2
    There are two schemas. 'mdbdev' is the master database and 'devusr' is granted SELECT table access to execute queries in mdbdev schema.
    with devusr, in SQL, I'm able to execute the following query
    select wm_concat(strConcatedCountryList)
    from (select country_name as strConcatedCountryList from mdbdev.country_master mdbcm
    where mdbcm.country_ship_status = <param?>
    order by country_name)
    but when I use the same query in function/procedure with "select into", the compilation failed with error *"table or view does not exist"*
    FUNCTION GETCOUNTRYLISTTOSHIP (SHIP_STATUS IN NUMBER)
    RETURN VARCHAR2
    IS
    var2CountryList VARCHAR2(1000);
    BEGIN
    select wm_concat(strConcatedCountryList) INTO var2CountryList
    from (select country_name as strConcatedCountryList from mdbdev.country_master mdbcm
    where mdbcm.country_ship_status = <value of SHIP_STATUS>
    order by country_name);
    return var2CountryList;
    END;
    Please advise/help/hint :)

    David, Justine, Thank you. The facts from this forum post helped a lot to get the solution.
    The query helped a lot (select * from all_tab_privs_recd where owner = 'MDBDEV' and table_name = 'COUNTRY_MASTER").
    there was a grant using ???(donno wht DBA said) and no direct SELECT grant on that country_master to "devusr". grant command executed. Now, it works :)

  • Select in stored procedures 11g

    I come from MS Sql Server, so select statements in Oracle are confusing, I have only 3 days experience with Oracle 11g
    I have managed to use SELECT INTO in my SP
    Can anyone provide an example of select using a for loop_+  AND  an example of select using BULK COLLECT_+???
    Edited by: user12146310 on Nov 8, 2009 3:51 AM

    Hi,
    The error tells you that the owner of AB_SELECT_BULK_COLLECT does not have a procedure called ANALYZE_COMPENSATION.
    Does he?
    select owner, object_name, object_type
      from all_objects
    where object_name in ('AB_SELECT_BULK_COLLECT', 'ANALYZE_COMPENSATION');Furthermore, in general when you can do something in SQL you should do it it in SQL only. I.e. without PL/SQL.
    You are doing "something" with all employees, this tells me that, that something maybe could and therefore should be done in a single SQL statement.
    Final thing, look into packages. Don't write stand-alone functions and procedures.
    Regards
    Peter

  • SELECT INTO ( variable ) STATEMENTS NOT WORKING FOR SYBASE TABLE AS VIEW

    Dear Experts,
    We have connected our 9i db with Sybase db using Hs connectivity.
    and then we have create the view in oracle db for SYBASE_TABLE as SYBASE_TABLE_VIEW.
    ALL THE INSERT, UPDATE AND DELETE COMMANDS ARE WORKING BUT THE
    select Into (variable) is not working.
    Please help to resolve the select into statment which is in BOLD in the below routine
    PLEASE NOTE! FORM WAS COMPILED SUCCESSFULLY AND FORM IS RUNNING BUT SELECT INTO COMMAND IS NOT WORKING.
    Thanks & Regards
    Eidy
    PROCEDURE SRBL_INSERT IS
    CURSOR SRBL IS
         SELECT impno,impcod,impnam
         from oracle_table1 a, oracle_table2 b
         WHERE a.impcod=b.empcod
         v_srpcod varchar2(5);
    BEGIN     
    FOR rec in SRBL loop     
         begin
    select "im_code" into v_impcod                    
         from SYBASE_TABLE_VIEW
         where "im_code"=rec.impcod;
    exception when no_data_found then
         v_srpcod:=null;
    end;
    END LOOP;
    END;
    Edited by: Eidy on Aug 16, 2010 11:28 AM

    hellow
    try this.
    select "im_code" into v_impcod
    from SYBASE_TABLE_VIEW
    where "im_code"=rec.impcod;
    v_srpcod := v_impcod ;
    ........

  • SELECT-INTO prepared statement?

    Hi,
    I have a single-row select to execute. I don't know if the multi-row select functionality (ResultSets, etc.) should be used for a single-select.
    Here's from the Oracle JDBC Documentation on a prepared statement with input variables:
    PreparedStatement pstmt =
    conn.prepareStatement ("insert into EMP (EMPNO, ENAME) values (?, ?)");
    pstmt.setInt (1, 1500); // The first ? is for EMPNO
    pstmt.setString (2, "LESLIE"); // The second ? is for ENAME
    pstmt.execute ();
    What I would like to do is have a PreparedStatement for output variables in a SELECT-INTO:
    pstmt= conn.prepareStatement("select max(sal) into ? from emp;");
    but there appears to be no bind variable functionality.
    Callable statements apparently are only for stored procedures.
    Basically, should I just use the multirow select for this?
    Thanks,
    Glen

    pstmt= conn.prepareStatement("select max(sal) into ?
    from emp;");
    but there appears to be no bind variable
    functionality.You might be able to bind this as an output parameter, but it seems like extra work (just getting a ResultSet for "select max(sal) from emp" would be a lot more straight forward).
    >
    Callable statements apparently are only for stored
    procedures.Not really, I execute PL/SQL blocks using prepared statements all the time. Sometimes it's the only way to get the data into a format that JDBC can handle.
    Here's an example:
        /** This is the SQL used to call the API ... */
        public static final String spSQL =  
        "declare " +
            "t_warranty_tbl apps.cib_devo_wrapper.wartbltyp; " +
            "x_warranty_tbl apps.cib_devo_wartbltyp; " +
            "x_return_text VARCHAR2(2000); " +
        "begin " +
            "apps.cib_devo_wrapper.cib_get_warranty_info(" +
                "P_SERIAL_NUMBER => ?,"
                "X_WARRANTY_TBL => t_warranty_tbl," +
                "X_RETURN_TEXT => x_return_text," +
                "x_row_count => ?); " +
            // Convert to a table of objects ...
            "x_warranty_tbl := apps.cib_devo_wrapper.cib_warranty_casttowartbltyp(t_warranty_tbl); " +
            // Get the cursor with order by ...
            "OPEN ? FOR SELECT * FROM TABLE(CAST(x_warranty_tbl AS apps.CIB_DEVO_WarTblTyp)) tbl " +
                "WHERE tbl.entitlementReturnCode != apps.cib_devo_wrapper.g_ent_ret_code_08 " +
                "ORDER BY tbl.INSTALLEDAT_CUSTOMER_NAME, tbl.SITE_NAME, tbl.SITE_ID, " +
                          "tbl.PRODUCT_FAMILY, tbl.PRODUCT_NAME, tbl.SERIAL_NUMBER; " +
           "?:=x_return_text; " +
        "end;";In this example, I declare a few variables, call a stored procedure,
    do some more PL/SQL to reduce the results before I finally bring them back.
    The first placeholder (question mark) is the input serial number, the second one is an output parameter that gives the row count. The third
    question mark is the cursor that contains the data I need, and the fourth is a reference to a status message.
    As you can see, the PL/SQL isn't exclusively stored procedure calls.
    >
    Basically, should I just use the multirow select for
    this?I think you'd need code that looks something like:
    DECLARE
    myCount NUMBER;
    BEGIN
    select max(sal) into myCount
    from emp;
    ? := myCount
    END;Although wrapping the select in a BEGIN..END block may be enough.

  • Cannot SELECT into a user-defined type variable

    Hi All,
    Oracle 11.2 on Linux.
    See the steps below. I am not able to insert/select into a TYPE variable. I do not want to do a TABLE declaration in my PL/SQL block, but want to use a user defined type. Is it possible ?
    SQL> create or replace type sample_obj_rec as object
      2  (
      3     object_id    number,
      4     object_name  varchar2(32),
      5     object_type  varchar2(32)
      6  );
      7  /
    Type created.
    SQL> create or replace type sample_obj_tab as table of sample_obj_rec ;
      2  /
    Type created.
    -- ------------   CASE 1 ---------------------
    SQL> declare
      2      v_tab   sample_obj_tab := sample_obj_tab() ;
      3  begin
      4      select object_id, object_name, object_type
      5      bulk   collect into v_tab
      6      from   dba_objects
      7      where  rownum < 11 ;
      8  end ;
      9  /
        from   dba_objects
    ERROR at line 6:
    ORA-06550: line 6, column 5:
    PL/SQL: ORA-00947: not enough values
    ORA-06550: line 4, column 5:
    PL/SQL: SQL Statement ignored
    -- ------------   CASE 2 ---------------------
    SQL> declare
      2      v_rec   sample_obj_rec;
      3  begin
      4      select object_id, object_name, object_type
      5      into   v_rec
      6      from   dba_objects
      7      where  rownum = 1;
      8  end ;
      9  /
        from   dba_objects
    ERROR at line 6:
    ORA-06550: line 6, column 5:
    PL/SQL: ORA-00947: not enough values
    ORA-06550: line 4, column 5:
    PL/SQL: SQL Statement ignoredWhat is the issue with both the above cases? what am I missing here?
    Thanks in advance.

    One small detail in the SELECT.
    SQL> create or replace type sample_obj_rec as object
      2  (object_id    number,
      3   object_name  varchar2(32),
      4   object_type  varchar2(32));
      5  /
    Type created.
    SQL>
    SQL> create or replace type sample_obj_tab as table of sample_obj_rec ;
      2  /
    Type created.
    SQL>
    SQL> declare
      2     v_tab   sample_obj_tab := sample_obj_tab() ;
      3  begin
      4     select sample_obj_rec(object_id, object_name, object_type)
      5     bulk   collect into v_tab
      6     from   dba_objects
      7     where  rownum < 11 ;
      8  end ;
      9  /
    PL/SQL procedure successfully completed.
    SQL>

  • Split Output from Select into 2 different Cols

    Hi,
    I am new to oracle dev. Env Oracle 10g R2
    I need a help with the following.
    I have a select query that returns comma separated values.
    Column LIST1 in table svp_1.
    This needs to hold that data returned by the select query.
    Datatype of Column LIST1 varchar2(4000)
    I get the follwing error.
    ORA-19011: Character string buffer too small
    CREATE OR REPLACE PROCEDURE
    sale_temp( pType in Char,lDate in date) as
    cnt number;
    v_error_code NUMBER;
    v_error_msg VARCHAR2(2000);
    cursor c1 is select svp
    from sale
    where type = pType
    var1 c1%ROWTYPE;
    BEGIN
    UPDATE svp_1
    SET LIST1 = ( SELECT LTRIM( xmlagg (xmlelement (c, RTRIM(RELATED_SVP) || ',')).extract ('//text()'), ',' ) AS RELATED_SVP from (
    SELECT rtrim(BASE_SVP) BASE_SVP,
    rtrim(RELATED_SVP) RELATED_SVP
    from
    svp_enc se
    where
    se.effective date<= pDate
    and (se.expiration_date is null or se.expiration_date > plDate )
    and se.base_svp in
    ( var1.svp
    and se.RELATION_TYPE = '4'
    )group by base_svp)
    WHERE type = pType
    commit;
    dbms_output.put_line('UPDATE done' );
    end;
    end loop;
    close c1;
    END ;
    My requirement :
    In need to capture the data from the select query and update the column.
    The data needs to be returned as comma separated values.
    This data can also be split into 2 columns.....ie data split and updated into 2 cols ie LIST1 AND LIST2 ( can be added to existing table).
    What is the best way to do this?
    Is the below approach possilble?
    LOOP through cursor ...check the length of data....for the select query ....check length .if > 3990 byte.....then write into 2 plsql variables.....and update 2 cols....
    Is this apporach right, if so how to do that in the procedure ? Please give an example...
    Are there any other approaches...?
    All I need is to Split Output from Select into 2 different columns and avoid the ORA-19011: Character string buffer too small error.
    Thanks in advance.

    Re: ORA-19011: Character string buffer too small

  • SELECT INTO clause strange problem

    Hi all,
    I need some help with a very strange select into statement.Select into throws NO DATA exception even if table has data.
    I am trying to invoke procedure from BPEL.Inside the procedure,I am trying to get "name' from definitions table.But it always throws Data NOT Found exception.But table has relevant data and i am able to see the data by executing the same query outside the BPEL environment/flow(SQL PLUS).
    Also,I kept dummy test table for Debugging purpose and it inserted with temp value '103'.
    My procedure looks like below
    temp:='103';
    INSERT INTO test
    VALUES ('Test-1' ||dummy,sysdate);
    commit;
    SELECT name
    INTO p_name
    FROM definitions
    WHERE id =temp;
    Please help me in this regards
    Thanks in advance.

    Hi Frank,
    Thanks for quick response.
    My actual query is
    dummy:=assume getting_valid_value from BPEL(also same dummy inserting into temp value);
    SELECT organization_code
    INTO p_warehousename
    FROM org_organization_definitions
    WHERE .organization_code = dummy;
    What are the schemas involved? APPS
    (Who owns the table?
    Who own the procedure? APPS
    Is it defined with "AUTHID CURRENT_USER"? NO IDEA
    Who runs it when you get the error? Thru BPEL actually
    What runs the same query in SQL*Plus and sees a row?). v*alid value(ALF)*
    I checked with low level security query as it returns nothing.
    thanks

  • Regarding "select into" query and "no data found" exception

    So i have included the following into my procedure:
    select div_cd into c_div_cd
                   from division_tab d, emp_tab y
                   where d.div_name=y.div_text and y.emp_code=d.emp_code;
    and also an exception
    exception
    when no data found
    -- print something
    The above select query results into "no data found" and the control passes directly to the exception and prints something.
    How do I do the following?
    select div_cd into c_div_cd
                   from division_tab d, emp_tab y
                   where d.div_name=y.div_text and y.emp_code=d.emp_code;
    if c_div_cd is null then
    --enter this employee into some other table without raising an exception
    No need to write a code for an answer. Please just guide me with something I can incorporate or do.

    use explicit cursors
    DECLARE
    c_div_cd division_tab.div_cd%type;
    cursor c_div is
    select div_cd
    from division_tab d, emp_tab y
    where d.div_name=y.div_text and y.emp_code=d.emp_code;
    BEGIN
    open c_div;
    fetch c_div into c_div_cd;
    --You can either use c_div%NOTFOUND or c_div_cd is null in the below if condition to check the data
    -- Note if your select query returns multiple records then you have to do mutiple fetches for getting all records, so in that case your FETCH
    -- should be inside the LOOP statement
    if c_div_cd is null then
    --enter this employee into some other table without raising an exception
    end if;
    close c_div;
    EXCEPTION
    IF c_div%ISOPEN then
    close c_div;
    END IF;
    END;
    Regards
    JJ

  • Converting MS-Access select * into... to run in Oracle

    I have this stored procedure in MS Access:
    create procedure foo as
    begin
    if exists(select name from sysobjects where name='cif_retail)
    drop table 'cif_retail'
    select * into cif_retail from cif where cstresf=1
    end
    The above stored procedure checks if table cif_retail exists and if it exists it drops it and then it creates a new table cif_retail with data from cif with the condition cstresf=1.
    How can I do the above in Oracle SQL? I tried the following but it comlains about the drop command, and when i remove it, it complains about the create table command too. Please help:
    create or replace procedure foo as
    begin
    drop table w;
    CREATE TABLE w AS SELECT * FROM x;
    end;
    Thanks,
    Theodora

    You can Also Use
    FORMS_DLL
    Example
    PROCEDURE Create_N_Column_Number_Table (n NUMBER) IS
    my_stmt VARCHAR2(2000);
    BEGIN
    my_stmt := 'create table tmp(COL1 NUMBER';
    FOR I in 2..N LOOP
    my_stmt := my_stmt||',COL'||TO_CHAR(i)||' NUMBER';
    END LOOP;
    my_stmt := my_stmt||')';
    ** Now, create the table...
    Forms_DDL(my_stmt);
    IF NOT Form_Success THEN
    Message ('Table Creation Failed');
    ELSE
    Message ('Table Created');
    END IF;
    END;

  • Passing function value into another procedure

    Hi
    From this package the value returned by the function " FIRST " needs to pass into another procedure as parameter in the same package, how could i do that in a better way.Oracle Version 8.1.7.4.0.
    CREATE OR REPLACE package body PKG_CUST_CHECK is
    FUNCTION FIRST(P_PARMS in varchar2) return varchar2 is
    l_parms varchar2(62) := P_PARMS;
    BEGIN
    SECOND(l_parms);     
         return(l_parms);     
    END;
    PROCEDURE SECOND(P_PARMS in out varchar2) is
    L_CUST Varchar2(30);
    BEGIN
    SELECT P_CUST INTO L_CUST FROM TABLE_A WHERE ROWNUM=1 ;
    THIRD(P_CUST in VARCHAR2,
    P_PARMS_VALID out VARCHAR2,
    P_OK_FOR_CUST out VARCHAR2,
    --Here the output of the above procedure will be concatinate and Return ;     
    END CUST_CHECK;
    end PKG_CUST_CHECK ;
    Thanks

    sorry for the confusion, not sure whether it will be clear enough.
    the requirement is function "FOURTH" should get the value returned
    by the function "FIRST" as in parameter value.
    [ code ] CREATE OR REPLACE package body PKG_CUST_CHECK is
    FUNCTION FIRST(P_PARMS in varchar2) return varchar2 is
    l_parms varchar2(62) := P_PARMS;
    BEGIN
    SECOND(l_parms);     
    return(l_parms); --here the value which is returning is updated one by the THIRD procedure       
    END;
    PROCEDURE SECOND(P_PARMS in out varchar2) is
    l_parms varchar2(62) := P_PARMS;
    BEGIN
    --the procedure THIRD will get the parameter values after
    --extracting the values from l_PARMS by another function EXTRACT
    THIRD(P_CUST in VARCHAR2,
    P_PARMS_VALID out VARCHAR2,
    P_OK_FOR_CUST out VARCHAR2,
    return;                    
    --Here the output of the above procedure will be concatinate and Return ;     
    END CUST_CHECK;
    FUNCTION FOURTH(P_PARMS in varchar2) return varchar2 is
    l_parms varchar2(62) := P_PARMS;
    BEGIN
    --the procedure FIFTH will get the parameter values after
    --extracting the values from l_PARMS by another function EXTRACT
    FIFTH(P_CUST in VARCHAR2,
    P_PARMS_VALID out VARCHAR2,
    P_OK_FOR_CUST out VARCHAR2,
    return;                    
    --Here the output of the above procedure will be concatinate and Return ;     
    END CUST_CHECK;
    end PKG_CUST_CHECK; [ /code ]

  • How to SELECT * into a SQL table incremntally by date?

    I have a SQL Server table called "tblProducts".
    Sometimes I backup this table by making a copy of it with this simple query:
    SELECT *
    INTO [test01].[dbo].[tblProducts_20141206]
    FROM [test01].[dbo].[tblProducts]
    Every time when making a backup, the date is included in the table name.
    I would like to create a SQL Job that runs this kind of query once every week.
    Is it possible to maybe in a stored procedure or declaring a variable to achieve this that allows the backed-up table name to be named like [tblProducts_todaysDate]?
    Thanks.

    hi ,dchencm
    i just want to point out the some bad effect of this pratice
    first point is
    when your db has be corrupt,your backup out of work
    i think you should backup your table to other db ensure that when your db has be corrupt you still have real backup
    just like
    SELECT *
    INTO [test01_backup].[dbo].[tblProducts_20141206]
    FROM [test01].[dbo].[tblProducts]
    another point is your pratice is total amount of backup not  incremental backup
    when your table  become bigger and bigger ,and then the number of record reach several million or several ten million or several hundred million, you must import all  data the table have
    so, this is not a good idea
    i just suggest  apply replication or logshipping etc to copy the diff data the table proceded is the better
     the steps of detail  as following
    step 1
    USE [test01]
    GO
    /****** 对象: StoredProcedure [dbo].[sp_ImportBackupData] 脚本日期: 12/25/2010 16:47:49 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE PROCEDURE [dbo].[sp_importbackupdata]
    AS
    BEGIN
    BEGIN
    DECLARE @date DATETIME ,
    @sql VARCHAR(1000)
    SET @date = GETDATE()
    SET @sql = 'SELECT * INTO [test01].[dbo].[tblProducts_'
    + CONVERT(VARCHAR(8), @date, 112)
    + '] FROM [test01].[dbo].[tblProducts]'
    EXEC (@Sql)
    END
    END
    step 2
    USE [msdb]
    GO
    /****** 对象: Job [import data] 脚本日期: 02/22/2011 09:22:44 ******/
    BEGIN TRANSACTION
    DECLARE @ReturnCode INT
    SELECT @ReturnCode = 0
    /****** 对象: JobCategory [Database Engine Tuning Advisor] 脚本日期: 02/22/2011 09:22:44 ******/
    IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'Database Engine Tuning Advisor' AND category_class=1)
    BEGIN
    EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'Database Engine Tuning Advisor'
    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
    END
    DECLARE @jobId BINARY(16)
    EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'sp_importbackupdata',
    @enabled=1,
    @notify_level_eventlog=0,
    @notify_level_email=0,
    @notify_level_netsend=0,
    @notify_level_page=0,
    @delete_level=0,
    @description=N'sp_importbackupdata',
    @category_name=N'Database Engine Tuning Advisor',
    @owner_login_name=N'sa', @job_id = @jobId OUTPUT
    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
    /****** 对象: Step [import data] 脚本日期: 02/22/2011 09:22:44 ******/
    EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'import data',
    @step_id=1,
    @cmdexec_success_code=0,
    @on_success_action=1,
    @on_success_step_id=0,
    @on_fail_action=2,
    @on_fail_step_id=0,
    @retry_attempts=0,
    @retry_interval=0,
    @os_run_priority=0, @subsystem=N'TSQL',
    @command=N'exec sp_importbackupdata',
    @database_name=N'sss',
    @flags=0
    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
    EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
    EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'import frequency',
    @enabled=1,
    @freq_type=8,
    @freq_interval=2,
    @freq_subday_type=1,
    @freq_recurrence_factor=1,
    @active_start_time=20000
    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
    EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
    COMMIT TRANSACTION
    GOTO EndSave
    QuitWithRollback:
    IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
    EndSave:
    the schedule time is 2 am  in the midnight  every monday 
    Certainly, you can edit it for yourself

  • Help with select into please

    Good morning everyone,
    I have a problem with my function. I need to do the dynamic select with the SELECT INTO
    create or replace function prueba (p_param IN VARCHAR2) RETURN VARCHAR2
    IS
    v_aux1 VARCHAR2(200);
    v_aux2 VARCHAR2(200);
    BEGIN
    SELECT col1
    INTO v_aux1
    FROM my_table
    WHERE col2 = p_param; --UNION SELECT '1233' FROM DUAL;
    RETURN v_aux1;
    EXCEPTION
    WHEN OTHERS THEN
    RAISE_APPLICATION_ERROR(-20000,SQLERRM );
    --RETURN v_aux2;
    END;
    When I try to call my function with the golden as follows:
    select (prueba('''MON'' UNION SELECT '||chr(039)||'12'||chr(039)||' FROM DUAL')) from dual
    OR
    select (prueba(chr(039)||'MON'||chr(039)||' UNION SELECT '||chr(039)||'12'||chr(039)||' FROM DUAL')) from dual
    I get the error: no data found
    If I use the sentence in Golden or SQLPLUS as follows:
    SELECT col1
    -- INTO aux1
    FROM my_table
    WHERE despaise = 'MON' UNION SELECT '12' FROM DUAL
    It ´s correct, and it return '1233'
    The value 'MON' no exists in my_table.
    If uncommented the sentence "UNION SELECT '1233' FROM DUAL" in my function an I use 'MON' as parameter it´s correct.
    How I can do this using the parameter with the UNION?.
    Thank you very much to all and sorry for my english

    Hi,
    welcome to the forum.
    Please read SQL and PL/SQL FAQ
    When you put some code or output please enclose it between two lines starting with {noformat}{noformat}
    i.e.:
    {noformat}{noformat}
    SELECT ...
    {noformat}{noformat}
    you cannot pass static SQL as part of the string.
    When you call the procedure in either wayselect (prueba('''MON'' UNION SELECT '||chr(039)||'12'||chr(039)||' FROM DUAL')) from dual
    select (prueba(chr(039)||'MON'||chr(039)||' UNION SELECT '||chr(039)||'12'||chr(039)||' FROM DUAL')) from dual
    This result in passing a whole string to your function as'MON' UNION SELECT '12' FROM DUAL
    which translates in your code asSELECT col1
    INTO v_aux1
    FROM my_table
    WHERE col2 = '''MON'' UNION SELECT ''12'' FROM DUAL'
    So it is searching a rows having col2 with value  '''MON'' UNION SELECT ''12'' FROM DUAL'
    Please try to explain what you are trying to achieve and we may help you.
    You could use dynamic SQL to do that but it is not clear what are your business requirement and the approach that you are using does not seem to be correct.
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for

  • Iphoto can't find my photos -- how can I force it to recognize them?

    I initially used iPhoto in referenced mode, but after a few years, I switched to managed mode, and then I inquired about how to make my iPhoto library entirely managed. About 2 years ago, Larry HN suggested Alias herder. I finally got around to using

  • Paper tray error message HP LaserJet 1102w

    Recently my LaserJet 1102w stopped printing duplex; instead, after printing the first side it gives an error message :  Paper tray needs to be filled.   The paper tray is full, but I cannot get it to continue printing the other side, no matter what.

  • F110 already run - how to reverse clearing manually

    Hi, I am facing a problem with F110 which had the Payment Run made by mistake. This run printed checks that were voided via ENVIRONMENT > CHECK INFO > VOID > ISSUED CHECK The objective was just to void checks without affecting FBL1N balance that is n

  • Page Size in reports 6i

    By default the page size in D2k reports (forms 6i) is 80 colum i.e. 8 1/2x11. How can i enlarge the page size..i.e. i want to make if fanfold 15x12 inch i.e. 132 colum .How do i go about it? please help.

  • How can I convert a PDF with a XFA file format

    I have an application that reader will not send, and it will not let me convert it to word or any other format.  I keep getting an error message that forms with an XFA format are not compatible.