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;

Tags: Oracle Development

Similar Questions

  • 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

  • How to use a SELECT QUERY using fdmAPI.executeDML in the Jython Script FDMEE?

    Hello

    Is just the way we use DELETE and INSERT statement using fdmAPI.executeDML, possible to run a SELECT statement and get the result in the variables?

    I want to refrain from using import java.sql and enter the connection information in a script. I would rather use SELECT directly if possible. I want to read the TDATASEG. DATAKEY column and use it for some custom in a custom table process

    Thank you!

    Try RS.next instead of RS. Next

  • How to write the select query for it

    Hello

    I had an html form and the area I drop down and he needs to select several values in the drop-down box. When I select multiple values then I have to write the query to SQL select statement.

    When I try to write the select statement and trying to run I get the error message.

    Select * from Table

    where emo_no = '1,2,3 '.

    That's how I write the query please suggest me how to write the query to select several values in the drop-down box.

    Thank you

    Use the keyword sql 'in '.  If you don't know how, I've heard good things about the book Teach Yourself SQL in 10 Minutes by Ben Forta.

  • How to get a select statement to pass a variable as the OUT parameter in PROC

    I have the underside of the nested select statement that returns the name of the missing table (data_table_name).

    How to be an effective way to modify the select statement, so that the returned 'data_table_name' is passed as OUTPUT in a procedure parameter
    select 'Missing Table Name : ' || data_table_name
         from   ( select upper(data_table_name) data_table_name
                  from   TABLE1
                  where  data_table_name in ('ABC',EFG','XYZ')
                MINUS
              ( select upper(fus_data_table_name)
                from   TABLE2
                where  fus_data_table_name in ('EFG',')
              group by
                     upper(fus_data_table_name)
              union
              select upper(fus_data_table_name)
              from   TABLE2
              where  fus_data_table_name = 'LMN'
              group  by
                     upper(fus_data_table_name)
            ));
    Any help is greatly appreciated.

    S
    CREATE OR REPLACE PROCEDURE myproc (tname OUT NOCOPY VARCHAR2) AUTHID CURRENT_USER IS
    BEGIN
      SELECT something
      INTO tname
      FROM whatever;
    EXCEPTION
      WHEN OTHERS THEN
        tname := ;
    END myproc;
    /
    
  • How to run DBMS_HS_PASSTHROUGH with the name of the variable database link?

    Hello

    I want to run some native sql through DBMS_HS_PASSTHROUGH of oracle to sybase.
    but the name of the database link is variable, from things as below:
    BEGIN DBMS_HS_PASSTHROUGH. OPEN_CURSOR@db_link_name;

    where db_link_name is a local variable and pl/sql still communicate compile error.

    Have experience with this?

    Thank you.

    Rock
    INTO l_cursor
    

    I think you mean...

    USING OUT l_cursor
    
  • How to see the info of waiting events. After executing a statement select query

    Hello

    How to see the info of waiting events. After running a select query. Is there a setting to the value of this option?
    And I also want to see the following info. in the trace file. For this, what are the settings I need to adjust to the right?
    SELECT * FROM emp, dept 
    WHERE emp.deptno = dept.deptno;
    
    call   count      cpu    elapsed     disk    query current    rows
    ---- -------  -------  --------- -------- -------- -------  ------
    Parse      1     0.16      0.29         3       13       0       0
    Execute    1     0.00      0.00         0        0       0       0
    Fetch      1     0.03      0.26         2        2       4      14 
     
    Misses in library cache during parse: 1 
    Parsing user id: (8) SCOTT 
    Concerning
    Evelyne

    For

    SQL > show parameter dump;

    ORA-00942: table or view does not exist
    >
    Use

     GRANT SEECT ON v_$parameter to Your_User_Name
    

    For

    SQL > ALTER SESSION SET EVENTS = 10046 trace name forever, context level 12';

    ERROR:
    ORA-01031: insufficient privileges
    >
    Use

     GRANT ALTER SESSION to your_user
    
  • 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

  • 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.

  • How to run a query to update on the results to a spreadsheet

    Hey there,
    I'm new to this kinda thing.
    I received a spreadsheet that has 2 tablets, 1 is called SQL generates and has a ton of data. 1 is called SQL statement and a select statement in the first cell.
    I said to run an update query by using the worksheet and received this:
    = CONCATENATE("Update CARDMEMBERISSUE set CURRSTATUSCD = 'ACT', DATELASTMAINT = sysdate where AGREENBR =",A2,"and MEMBERNBR =",B2,"and ISSUENBR =",C2,";")

    = CONCATENATE("Insert into CARDMEMBERISSUEHIST (AGREENBR, MEMBERNBR, ISSUENBR, EFFDATETIME, CARDSTATCD, STATREASON, DATELASTMAINT, DATESENT) values (', A2, ',', B2, ',', C2", sysdate, 'Law', null, sysdate, null);' ")

    I don't know what to do or how to do this.
    It's that the lines in the worksheet as look, including the column header, A1 is empty.
    A B C etc.
    NBR MEMBERNBR QUESTION NBR CURRSTATUSCD PREFIX CARD NBR AGREETYPCD NBR EXT CARD ISSUE DATE PERS OWNER AGREE
    2 12 1 44 ISS g 22 22 19/10/2011

    = CONCATENATE bits are Excel formulas. Assuming that they properly drafted, they generate a set of individual sql statements. The first concaenatewill generates a set of instructions to update on the CardMemberIssue table, and the second will generate a set of insert statement in the CardMemberIssueHist table.

    You should be able to simply paste the instructions generated in any tool that you use to run sql to run. Before you do this right, make sure that you are running:

    alter session set cursor_sharing=force;
    

    before sticking anything in.

    John

  • How do I check how much time running on the query server

    Hello

    I work as a junior DBA. The guys on the team application gives the SID from v$ session and asking me how long running this query.
    I'm connecting ther server and get the PID and cpu utilization on unixbox, but cannot get it question time.
    Pls help help get duration/how running queries. Verion Oracle's 9i.

    SQL > select * from v version $;

    BANNER
    ----------------------------------------------------------------
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
    PL/SQL Release 9.2.0.8.0 - Production
    CORE Production 9.2.0.8.0
    AMT for Solaris: 9.2.0.8.0 - Production Version
    NLSRTL Version 9.2.0.8.0 - Production

    Kind regards
    Vincent

    >
    This means 113547 minutes. Right?
    >

    Yes, it's true. But it is not a few Minutes but microseconds. ELAPSED_TIME is microseconds (10g or higher. Not sure about 9i. Please check the doc)

    >
    Number of executions increasing very fast now its 29999. with in wrigting mail its increase. to get the output why this query execution of this many times.
    >

    This means there are a few sessions by running the same query (which is fine). Only, you will need to tell us why the query is run that many times :) Maybe, you need it!

    Published by: user12035575 on September 11, 2011 14:38

  • How to use a parameter query to select and display the data in the table of the façade

    Hiiiiii

    I am using Access 2007 database
    I want to select the specific data in the database using control of the chain as 'select product, size, weight of ProductInfo where barcode (chain control) =?'  and also display the same table of façade.

    I use the connected database toolkit.
    I saw the example of the parameterized insert, but it did not help to use parameterized select query, as well as to display data of parameterized select query.

    I looked for example on parameterized select query, but I don't have any.
    So pls guide me how to do this. I would like to know the other method (if any) that the use of parameter query to perform the same thing.
    If possble pls share a vi reference.
    Thank you!!!

    HII szewczak
    Thanks for the reply
    but I did not getsolution in one of your shared links
    My problem is solved. There is no need to use the parameter query to select control values
    In my case I want to display data from database where bar code is even entered by the user
    I use the data function DB TOOL CHOOSE and create the condition of chain based on concatenation of strings

  • 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 write a simple select query to get the data of the table as an XML.

    How to write a simple select query to get the data of the table as an XML. In the query, I'm just adding items below which i need be there in the XML document
    select '<test_tag>'||EMP_NAME||'</test_tag>','<date>'||sysdate||'</date>' 
    from temp_table where id_num BETWEEN 1 AND 10;
    I have need to add the root tag as well in the beginning and the end of < root > < / root > this xml file. Please advice if this is possible with the select query
    without using XMLGEN, XMLQUERY or any other packages built and function?

    I need to URL escapes with the UTF-8 code points that we have already achieved using the utl_http package. Please help how to do that without using the utl_http package.

    What is wrong with him?

    At present, the only way I can think of to avoid a call to UTL_HTTP. SET_BODY_CHARSET is to write your own little wrapper.
    In this way, you can specify the Boolean parameter or omit it if you choose to use named parameters:

    SQL> create or replace function my_url_escape (url in varchar2)
      2  return varchar2
      3  deterministic
      4  is
      5  begin
      6   return utl_url.escape(url, false, 'AL32UTF8');
      7  end;
      8  /
    
    Function created
    
    SQL> select my_url_escape('http://some.uri.com/param?lang=fr&text=contrôle') from dual;
    
    MY_URL_ESCAPE('HTTP://SOME.URI
    --------------------------------------------------------------------------------
    http://some.uri.com/param?lang=fr&text=contr%C3%B4le
     
    
  • How to run the query on load

    Hello
    I have a form based on the table that store only 1 card. I have created a form page, but may not know how to run the query and display the record in the table. If there is no record in the table, I want that the user can use this page to create a record.
    Thanks in advance
    NRI

    Hello Nri,

    What value does P18_SCHOOL_ID?
    If you look at the State of Session (toolbar) developer. If that does not have a value, it's your problem.

    You can create a calculation before the process that gives the correct value. (In one case more often, you have a report and when you click on the link change that id is activated and you see the recording in your form)

    Dimitri

Maybe you are looking for

  • How can I change the menu drop-down remembers passwords, email Add. or user name when I walked in the wrong?

    Or it could be a Windows 7 problem. My typing is not good, and sometimes the email or password are wrong typed.The drop-down menu you offers versions that I typed, including the right pair, if I put it.How can I get rid of the most useless, bad and e

  • incorrect gift card balance

    I bought a $15.00 gift card for my son me hand to the bottom of the iPad. (I didn't link a credit card to it)  The balance is listed at $4.21.  Nothing has been purchased since I bought the gift card to their account.  I checked the purchase history

  • Reboot loop after the configuration of the Windows updates

    original title: configuration to update windows, remains at 0% then restarts vista, now stuck in an endless loop, I can't break out of. my system is set up as a dual boot... my being main vista home... the other day I did my update systematic of wind

  • Letter Q, W, E, R, T, U, I, O do not work on my laptop... keyboard. What can I do?

    above letters are not workng on my keyboard. However, my keyboard propertie indicate that my device is working properly.This problem started a week ago. am currently using the screen keyboard to type.I need emergency solution.Thank you

  • Pushing NavigationPane TabbedPane

    I'm trying to push a TabbedPane of NavigationPane (main.qml). var nextPage = nav.deprecatedPushQmlByString("tabbedPane.qml"); It does not work. I know either (1) I'm doing something wrong (2) I do not understand what can or cannot be pushed some scre