SELECT query in a procedure

How to create a procedure to SELECT similar to the following query? When I create a procedure; I get an error.

  • "Error (80.1): PLS-00428: an INTO clause in the following SELECT statement.

PROCEDURE MyProc

IS

BEGIN

Select 'Dakota' as an ALIAS

A.StartDate

B.EndDate

customer A

, Customers b

where a.cType = b.cType

and b.Active = 0

ORDER BY StartDate, EndDate

MyProc END;

remove the; at the end of your query

Tags: Database

Similar Questions

  • Can get us data back from a stored procedure in a select query?

    Hello
    Suppose I have a function GetSum(x,y) that returns the sum of two numbers x and y. We can call this function from a function sql like this:
    select GetSum(4,5) SUM from dual;
    But it's possible thanks to a stored procedure? for example, can I call a stored procedure from a select query, as I did above code?

    bootstrap wrote:
    Hello
    Suppose I have a function GetSum(x,y) that returns the sum of two numbers x and y. We can call this function from a function sql like this:

    select GetSum(4,5) SUM from dual;
    

    But it's possible thanks to a stored procedure?

    NO!

  • How to convert my query in SQL procedure

    Hi all

    I run a SQL query in my process of page to set a few articles on my page.

    Start
    declare
    l_vc_arr2 APEX_APPLICATION_GLOBAL. VC_ARR2;
    Start

    IF APEX_APPLICATION. G_F01. COUNT = 0 THEN
    RAISE_APPLICATION_ERROR (-20001, 'Please select a model of e-mail to change!');
    END IF;

    IF APEX_APPLICATION. G_F01. COUNT > 1 THEN
    RAISE_APPLICATION_ERROR (-20001, 'Please select a model unique to change both message!');
    END IF;

    BECAUSE me in 1.APEX_APPLICATION. G_F01. Count
    LOOP
    l_vc_arr2: = APEX_UTIL. STRING_TO_TABLE (APEX_APPLICATION. G_F01 (i),' $');
    : P32_SUBJECT: = l_vc_arr2 (1);
    : P32_TYPE: = l_vc_arr2 (2);
    : P32_BODY: = l_vc_arr2 (3);
    END LOOP;
    end;
    end;

    It works perfectly fine. Now, I want to turn this query in custom procedure. I write the following code to create the SQL procedure,

    create or replace
    procedure Edit_EmailTemplate as
    Start
    declare
    l_vc_arr2 APEX_APPLICATION_GLOBAL. VC_ARR2;
    Start

    IF APEX_APPLICATION. G_F01. COUNT = 0 THEN
    RAISE_APPLICATION_ERROR (-20001, 'Please select a model of e-mail to change!');
    END IF;

    IF APEX_APPLICATION. G_F01. COUNT > 1 THEN
    RAISE_APPLICATION_ERROR (-20001, 'Please select a model unique to change both message!');
    END IF;

    BECAUSE me in 1.APEX_APPLICATION. G_F01. Count
    LOOP
    l_vc_arr2: = APEX_UTIL. STRING_TO_TABLE (APEX_APPLICATION. G_F01 (i),' $');
    v (P32_SUBJECT): = l_vc_arr2 (1);
    v (P32_TYPE): = l_vc_arr2 (2);
    v (P32_BODY): = l_vc_arr2 (3);
    END LOOP;
    end;
    end;

    but it is not compiling. Someone knows what's the problem?


    With respect,
    Sunil Bhatia

    Hi Sunil,

    You cannot use the function v ('P32_BODY') to assign values.

    you will need to use:
    apex_util.set_session_state ('P32_BODY', l_vc_arr2 (3));

    Concerning

    Michael

  • How to optimize the select query executed in a cursor for loop?

    Hi friends,

    I run the code below and clocked at the same time for each line of code using DBMS_PROFILER.
    CREATE OR REPLACE PROCEDURE TEST
    AS
       p_file_id              NUMBER                                   := 151;
       v_shipper_ind          ah_item.shipper_ind%TYPE;
       v_sales_reserve_ind    ah_item.special_sales_reserve_ind%TYPE;
       v_location_indicator   ah_item.exe_location_ind%TYPE;
    
       CURSOR activity_c
       IS
          SELECT *
            FROM ah_activity_internal
           WHERE status_id = 30
             AND file_id = p_file_id;
    BEGIN
       DBMS_PROFILER.start_profiler ('TEST');
    
       FOR rec IN activity_c
       LOOP
          SELECT DISTINCT shipper_ind, special_sales_reserve_ind, exe_location_ind
                     INTO v_shipper_ind, v_sales_reserve_ind, v_location_indicator
                     FROM ah_item --464000 rows in this table
                    WHERE item_id_edw IN (
                             SELECT item_id_edw
                               FROM ah_item_xref --700000 rows in this table
                              WHERE item_code_cust = rec.item_code_cust
                                AND facility_num IN (
                                       SELECT facility_code
                                         FROM ah_chain_div_facility --17 rows in this table
                                        WHERE chain_id = ah_internal_data_pkg.get_chain_id (p_file_id)
                                          AND div_id = (SELECT div_id
                                                          FROM ah_div --8 rows in this table 
                                                         WHERE division = rec.division)));
       END LOOP;
    
       DBMS_PROFILER.stop_profiler;
    EXCEPTION
       WHEN NO_DATA_FOUND
       THEN
          NULL;
       WHEN TOO_MANY_ROWS
       THEN
          NULL;
    END TEST;
    The SELECT inside the LOOP FOR cursor query took 773 seconds.
    I tried to use COLLECT in BULK instead of a cursor for loop, but it did not help.
    When I took the select query separately and executed with a value of the sample, and then he gave the results in a Flash of a second.

    All tables have primary key index.
    Any ideas what can be done to make this code more efficient?

    Thank you
    Raj.
    DECLARE
      v_chain_id ah_chain_div_facility.chain_id%TYPE := ah_internal_data_pkg.get_chain_id (p_file_id);
    
      CURSOR cur_loop IS
      SELECT * -- better off explicitly specifying columns
      FROM ah_activity_internal aai,
      (SELECT DISTINCT aix.item_code_cust, ad.division, ai.shipper_ind, ai.special_sales_reserve_ind, ai.exe_location_ind
         INTO v_shipper_ind, v_sales_reserve_ind, v_location_indicator
         FROM ah_item ai, ah_item_xref aix, ah_chain_div_facility acdf, ah_div ad
        WHERE ai.item_id_edw = aix.item_id_edw
          AND aix.facility_num = acdf.facility_code
          AND acdf.chain_id = v_chain_id
          AND acdf.div_id = ad.div_id) d
      WHERE aai.status_id = 30
        AND aai.file_id = p_file_id
        AND d.item_code_cust = aai.item_code_cust
        AND d.division = aai.division;         
    
    BEGIN
      FOR rec IN cur_loop LOOP
        ... DO your stuff ...
      END LOOP;
    END;  
    

    Published by: Dave hemming on December 4, 2008 09:17

  • Select conditional in stored procedure

    Select conditional in stored procedure

    I table a table b, I would like to do otherwise rank in table and select table.

    Otherwise, select table one

    airfare so I have the follow-up in the code, how do I call


    create or replace PROCEDURE of test (app_numb VARCHAR2, examtype out VARCHAR2) is

    v_counter number: = 0;

    REC cursor is

    Select * where appno = app_numb;

    BEGIN

    v_counter: = 0;

    FOR r loop rec

    v_counter: = v_counter + 1;

    end loop;

    If v_counter = 0 Then

    Select exam_type in the examtype of b;

    DBMS_OUTPUT. Put_line (examtype);

    On the other

    DBMS_OUTPUT. PUT_LINE ('ABCD');

    End if;

    PS it would be generally more appropriate for a procedure of "getter" is in fact a function and the return value as a RETURN statement, rather than using THE parameters, which are generally not a good method to return data.

  • SELECT query time-out - huge table

    DBA dear friends,


    DB version 11.1.0.7.  I have a SELECT query that is running long and wedging on. Query joins the 2 tables. It is partitioned hash (16 sheets) and others are not partitioned, each table is with the same volume of data - 230 million lines.

    > Optimizer stats are not outdated

    SELECT only 1 row (as indicated in the PLAN of EXPLAIN) should be fast.

  • Can I use * and the list of the column names in a select query

    PLSQL again.  Can I use * and the list of the column names in a select query, i.e. Select *, col1, col2 from Mytable.  When I do that my questions tend to the bomb.  Can do in other databases.

    Thank you

    Mike

    Hi, Mike,.

    If there is something else in the more SELECT clause *, then * must be qualified with a table name or alias.

    For example:

    SELECT Mytable. *, col1, col2

    FROM MyTable;

  • place a select query calculation in a different column in the same table

    How can I put my calculation result in a column named within the same table?

    I have a table called: dgpercentagedatachart

    I use the columns of this dgpercentagedatachart: totalcecrating divided by lowestfeederrating times 100 to get the percentage

    In the query, I gave the result the Alias of the cal

    What I want is to put this result in my application or my calculation (in percentage) in my column "percent" on my table of dgpercentagedatachart vacuum.

    How can I configure this syntax?

    This is the select query, I came with:

    Select dgpercentagedatachart.totalcecrating, dgpercentagedatachart.lowestfeederrating,.

    100.00*dgpercentagedatachart.totalcecrating/dgpercentagedatachart.lowestfeederrating as cal

    of dgpercentagedatachart;

    Here are the results:

    CAL lowestfeederrating Totalcecrating

    8,978 7.48166666666666666666666666666666666667 120

    30.951 25.7925 120

    5.04                         120                          4.2

    Hello

    2685870 wrote:

    How can I put my calculation result in a column named within the same table?

    I have a table called: dgpercentagedatachart

    I use the columns of this dgpercentagedatachart: totalcecrating divided by lowestfeederrating times 100 to get the percentage

    In the query, I gave the result the Alias of the cal

    What I want is to put this result in my application or my calculation (in percentage) in my empty column '%' on my table of dgpercentagedatachart .

    How can I configure this syntax?

    This is the select query, I came with:

    Select dgpercentagedatachart.totalcecrating, dgpercentagedatachart.lowestfeederrating,.

    100.00*dgpercentagedatachart.totalcecrating/dgpercentagedatachart.lowestfeederrating as cal

    of dgpercentagedatachart;

    Here are the results:

    CAL lowestfeederrating Totalcecrating

    8,978 7.48166666666666666666666666666666666667 120

    30.951 25.7925 120

    5.04                         120                          4.2

    To change an existing column in a table, you can use the UPDATE or MERGE, instructions like this:

    UPDATE dgpercentagedatachart

    Percentage of VALUE = 100,00 * totalcecrating

    / lowestfeederrating

    ;

    Noramlly, tables is not redundant columns like this.  If percent can always be calculated from other columns, then it is probably better to calculate at run time and store it in the database, where you will have to be updated each time the columns it depends on change.  You can use a view to avoid having to encode them the calculation.

    If you really don't want a column that can be calculated in the same lines other columns, then use a virtual column (if you use Oracle 11 or higher).

    I hope that answers your question.

    If this isn't the case, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.

    If you ask on a DML statement, such as UPDATE, the sample data will be the content of the or the tables before the DML, and the results will be the State of the or the tables changed when it's all over.

    Explain, using specific examples, how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: Re: 2. How can I ask a question on the forums?

  • Error in the SELECT query

    Hello

    Oracle version: 11g R2 (11.2.0.2)

    I get the following error message (I'm using TOAD for Oracle last version 12.1):

    ORA-12801: error reported in the parallel query P032 Server

    ORA-01114: block write IO file error (block #)

    ORA-01114: IO error to the file 201 (block # 2165248) writing block

    ORA-27072: IO file error

    Linux-x86_64 error: 28: no space is available on the device

    Additional information: 4

    When you run a SELECT query:

    SELECT field1, Field2...

    OF (REVENUE_SOURCE b

    INNER JOIN ACCOUNTS_CLASSIFICATION one

    WE b.SUB_ACCOUNT = a.SUB_ACCOUNT)

    INNER JOIN REPORT_PRODUCT_ID c

    ON b.REPORT_PRODUCT_ID = c.REPORT_PRODUCT_ID

    WHERE a.UC_BUSINESS_UNIT = 'ANX.

    AND b.report_mm > =.

    (SELECT ADD_MONTHS (MAX (report_mm),-13))

    OF REVENUE_SOURCE)

    AND b.REVENUE_FLAG = - 1

    AND (b.CALLS <>0 b.MINUTES <>0 b.CHARGE_AMOUNT GOLD <>GOLD 0);

    Please notify.

    NOTE: the query worked well for a while, no errors, then all suddenly it became much accentsr and then I started to get the error message above.

    Kind regards

    M.R.

    Hello

    ORA-27072: IO file error

    Linux-x86_64 error: 28: no space is available on the device

    Looks like a system or OS, no SQL or PL/SQL problem problem.  I think you will answer sooner if you check this issue as 'Response' and start a new question in the forum of "General Question":

    https://forums.Oracle.com/community/Developer/English/oracle_database/general_questions/content

    My guess is that Oracle tries to allocate space in the tablespace temp, but cannot because the disk is full.  If you have a full disk, then create the space to this topic.

    I see nothing wrong with your code; Certainly, nothing which would cause an error like that.  The fact that the query has worked well for some time confirms that there is noting wrong with the request itself; It is just triggering a mistake elsewhere.

  • SELECT query

    Hello

    First of all, I had two tables. The first PARAMETER called that inculdes three columns parameter_id (number), the parameter_desc (varchar2 (20) and (number) parameter_value.) The parameter_id is a PK. The INSERT statement might like this:

    Enter the parameter (parameter_id, parameter_desc, parameter_value) values (1, 'TEST1', 233);

    Enter the parameter (parameter_id, parameter_desc, parameter_value) values (2, 'TEST2', 456);

    Insert in the parameter (parameter_id, parameter_desc, parameter_value) values(3,'TEST3',678);

    And a second table, called TOPO_PARAM, which includes three columns (number) topo_id, parameter_id (number) and topo_param_value (varchar2 (10).) The PK is on topo_id and parameter_id. The insert for this one is

    insert into topo_param (topo_id, parameter_id, topo_param_value) values (349.1, 'FALSE');

    insert into topo_param (topo_id, parameter_id, topo_param_value) values (568,2, 'TRUE');

    I want a select query that links the two tables and returns this:

    If topo_id = 349

    I wish to have this:

    parameter_id parameter_value topo_param_value                   

    1                                   233                                   'FALSE'

    2                                   456                                    NULL

    3                                   678                                    NULL

    If topo_id = 568,

    parameter_id parameter_value topo_param_value                

    1                                   233                              NULL

    2                                   456                              'TRUE'

    3                                   678                              NULL

    And if topo_id = 500,

    parameter_id parameter_value topo_param_value              

    1                                   233                         NULL

    2                                   456                         NULL

    3                                   678                         NULL

    Thanks for your response!

    SELECT T1. PARAMETER_ID,

    T1. PARAMETER_VALUE,

    T2. TOPO_PARAM_VALUE

    THE PARAMETER T1 LEFT OUTER JOIN

    TOPO_PARAM T2

    ON T1. PARAMETER_ID = T2. PARAMETER_ID

    TOPO_ID = & INP

    ORDER OF T1. PARAMETER_ID;

    OUTPUT:

    Enter the value of the inp: 349
    7 old: AND TOPO_ID = & INP
    7 new: AND TOPO_ID = 349

    PARAMETER_ID PARAMETER_VALUE TOPO_
    ------------ --------------- -----
    1 233 FALSE
    2 456
    3 678

  • Formatting of the Select query

    The following select query returns the data in green.  How do I format to return the path that it is formatted in red?

    Basically, if FIELD1 is "Customer A" and FIELD2 is "Gas" then I back to 'New customer' Field1 and Field2 'gas '.  If 'Customer E' FIELD1 and FIELD2 is 'Total' then it should return 'E rejection' in Field1 and 'Prod_Discharge' in the Field2.

    Please let me know if my question is not sensible or need to be clarified.

    SELECT

    DECODE (Field1, 'Nine', ' A', 'Old', 'E', 'Term', 'F', Field1)

    DECODE (Field2, 'Prod', 'Gas', Field2)

    Customers

    FIELD1 FIELD2

    Customer A gas

    Customer has oil

    Total customers E

    Customer F Total

    Need to format as follows:

    Field1 Field2       

    New gas customer          

    New customer oil      

    E Prod_Discharged releases          

    F Prod_Discharged releases

    Try this:

    SELECT CustomerID

    , CASE WHEN field1 = 'Customer A' THEN 'new customer '.

    WHEN field1 = 'Customer E' AND field2 = 'Total' THEN 'E releases '.

    WHEN field1 = ' customer F ' AND field2 = 'Total' THEN 'F performs ".

    Of ANOTHER Field1

    FIELD1 AS END

    , CASE WHEN Field1 IN ('E of customer', ' customer F ') AND field2 = 'Total' THEN 'Prod_Discharged '.

    Of OTHER Field2

    END AS FIELD2

    Status

    Customers

    ;

  • as with the select query

    Hello

    I have a query something like...

    Select...

    ....

    where

    b.ProdName as 'GEAR of the TREE %' or b.prodname like '% FRONT GEAR %' or b.prodname like '% BREAK 4 %k '.

    and

    b.ProdName as

    (select the name of the society of companyms

    where < some comdition >

    )

    order of 3.6

    I have blocked in:

    b.ProdName as

    (select the name of the society of companyms

    where < some comdition >

    )

    How to give a select query with like operator.

    In above query I want to b.prodname as above and the name of the company for which I give condition.  Company names are stored in another table and I want to select and use them with like operator.

    Thank you.

    Hello

    It is not clear what you want to do.

    One possibility is an EXISTS subquery, like this:

    ...

    WHERE (b.prodname LIKE "% of the CYCLE of the TREE" - begins with this text

    OR b.prodname LIKE '% FRONT GEAR %' - contains this text

    OR b.prodname LIKE '% BREAK 4 %k' - contains this text

    )

    AND THERE ARE)

    SELECT 1

    OF companynms

    WHERE--a condition

    AND b.prodname AS business

    )

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • How to run a Select query stored in a Variable

    Hello

    I have a following requirement:

    Select a query result on Var1, result of another request selection in Var2,
    If Va2 = "value11" or Var2 = "Value2" then Var1 = "select query. Now how can I run this SQL at the end of the Pl/SQL query?

    so I write request for the same thing:

    DECLARE
    qry nvarchar2 (500);
    result nvarchar2 (500);

    BEGIN

    Select "choose TEXTVAL as 'CHARGER' FROM TABLE1 WHERE LOC =" [ParameterValue] "and KEYNAME =" < < REPLACE > > "' double INTO qry ;"

    SELECT CASE County WHEN (RW." CountofBATCH') > 1 then "mixture."
    WHEN count (RW." CountofMAT') = 0 then 'None '.
    ANOTHER 'other '.
    END
    AS a result
    TABLENAME2 TT, XMLTable ('/ sets of lines/lines/lines ' PASSAGE TT.) XMLCOL
    COLUMNS
    "CountofBATCH" PATH "/ row [CLABS > 0] / LOADED ',"
    "CountofMAT" PATH "/ row [MATNR = '[parameter value]'] / MAST '"
    ) AS RW

    where
    TT.PL = '[parameter value]' and
    TT. TANK = "[value settings]";

    IF result = 'Mixture' result GOLD = 'None' THEN
    qry: replace = (qry, "< < REPLACE > >", result);
    on the other
    qry: = 'nothing. '
    END IF;

    Thus the qry variable will have select statement. Now how can I use this to get the select result of this statement in the same query qry?

    You can use execute immediately if the output of the query is in the same query.

    It's very simple.
    a query string signle and then go like this

    declare
    qry VARCHAR2 (255);
    result varcharf2 (2500);
    number of vempid: = 1;

    Start
    qry: =' select empname emp where empid =: empid ";

    run immediately qry in the result using vempid;
    -now the result of data is as a result
    end;

  • Sinlge select query in the diff for the same table (same Structure) diagrams

    Scenario:

    Table XYZ is created in detail a.
    After a year, the old data of the previous year could be moved to another schema. However in the other schema of the same table name would be used.

    For example

    A schema contains XYZ table with data from the year 2012
    Schema B contains XYZ table with data for the year 2011
    Table XYZ in the two schemas have an identical structure.

    So we can draw a single select query to read the data from the tables in an effective way.
    For example select * from XYZ so including date between October 15, 2011 to March 15, 2012.
    However, the data resides in 2 different schema altogether.


    Creating a view is an option.
    But my problem, there are ORM (Hibernate or Eclipse Top Link) layer between the application and the database.
    If the queries would be constituted by the ORM layer and are not generated by hand.
    So I can't use the view.
    So is there any option that would allow me to use only query on different scheme?

    970773 wrote:
    Scenario:

    Table XYZ is created in detail a.
    After a year, the old data of the previous year could be moved to another schema. However in the other schema of the same table name would be used.

    For example

    A schema contains XYZ table with data from the year 2012
    Schema B contains XYZ table with data for the year 2011
    Table XYZ in the two schemas have an identical structure.

    So we can draw a single select query to read the data from the tables in an effective way.
    For example select * from XYZ so including date between October 15, 2011 to March 15, 2012.
    However, the data resides in 2 different schema altogether.

    Creating a view is an option.
    But my problem, there are ORM (Hibernate or Eclipse Top Link) layer between the application and the database.
    If the queries would be constituted by the ORM layer and are not generated by hand.
    So I can't use the view.

    Why not make the ORM as below?

    SELECT * FROM VIEW_BOTH;
    -VIEW_BOTH is a real VIEW of Oracle

  • Please suggest a select query / under query with using any routines or

    source table: three columns ORIGIN, DESTINATION, MILES

    Origin Destination Miles

    Sydney Melbourne 1000
    Perth, Adelaide 3000
    Canberra Melbounre 700
    Melbourne Sydney 1000
    Brisbane Sydney 1000
    Perth, Darwin 4000
    Sydney, Brisbane 1000

    out put: three columns ORIGIN, DESTINATION, MILES

    Duplicate routes should be ignored, so the output is

    Origin Destination Miles

    Sydney Melbourne 1000
    Perth, Adelaide 3000
    Canberra Melbounre 700
    Brisbane Sydney 1000
    Perth, Darwin 4000

    Please suggest a select query / under query with using subroutines or functions/pkgs to get put out table.

    Hello

    user9368047 wrote:
    ... Please suggest a select query / under query with using subroutines or functions/pkgs to get put out table.

    Why? If the most effective way to achieve the desired results is to use a function, why would you not use it?

    Here's a way, without all the features:

    SELECT     a.*
    FROM           source_table  a
    LEFT OUTER JOIN      source_table  b  ON   a.origin          = b.destination
                                          AND  a.destination       = b.origin
                          AND  a.miles          = b.miles
    WHERE   b.origin  > a.origin    -- Not b.origin > b.origin
    OR     b.origin  IS NULL
    ;
    

    If you would care to post CREATE TABLE and INSERT statements for your sample data, and then I could test this.

    Published by: Frank Kulash, November 6, 2012 19:39
    Fixed WHERE after MLVrown clause (see below)

Maybe you are looking for

  • Need help to store data

    Hello. I came here for advice how to store data. What I'm trying to do is to take the gains given by my DAQ and store all in a table as it is acquired in an organized manner (3-columns, with a time stamp.) So far, I looked at writing text .vi and wri

  • Cache objects VI shared between 32 and 64 bit?

    Transferred into the LAVA: http://lavag.org/topic/16349-vi-object-cache-shared-between-32-and-64-bit/page__pid__99898 I am currently working on a major project that is to be deployed in 32 - bit and 64-bit flavors. This means that I must periodically

  • Can not access the updates XP, 0x8024400A error message.

    I reformatted my HARD drive, reloaded XP SP2 Home. Download IE 8. I need XP SP 3, but now I can not access the updates... 0x8024400A error message. Help please

  • Sansa froze?

    Hello everyone. I think that my Sansa Fuze could be frozen... I plug the charger thing in my laptop, and then in the Sansa then it froze. I've seen the battery charging sign, but anything else would not move, no matter what I pressed. It has been a f

  • where can I see the photos 'print screen '?

    where can I see the photos 'print screen '?