How to execute a SQL statement that is stored within a SQL Table

Hello

If someone please help me with the following problem I would be eternally grateful

I have a SQL statement that is stored inside a certain SQL table, I want to use this SQL statement inside my PL/SQL procedure.

Thought a simple solution was to get the SQL statement in a table, and then run it, but how could I do so exactly with PL/SQL? I only started to play with PL/SQL in the last days.

Thanks in advance!

This is what it looks like more or less:

Display result for:

---------------------

SELECT TRIM (OBJ_VALU_TXT)

OF OBJ_VALU_DOC

WHERE TYPE_OBJET = 'FLD '.

AND OBJECT_CODE = 15443

AND OBJ_VALU_CD = 'CAB '.

ORDER BYDOC_SEQ_NO

00001

------------------------------------------------------------------

SELECT

VALUE (MAX (RECEIPT_NO) + 1,: OUT-COMP-FACTOR)

THE FRONT DESK

WHERE (RECEIPT_NO BETWEEN

(: OUT-COMP-FACTOR AND: OUT TO A NUMBER) OR

(RECEIPT_NO >: OUT-COMP-FACTOR AND)

(: OUT-TO-NUMBER = 0)

Here's a demo of your condition.

create table t (col1 varchar2 (200));

table created

insert into values t ('select * from double ');

1 row inserted

declare
v_col varchar2 (200);
v_val varchar2 (200);
Start

Select col1 in t v_col;

run immediately v_col in v_val;
dbms_output.put_line (v_val);
end;

-----
X

Use in the clause, you can use as many variables as needed. But the basic approach remains the same.

But storage in DB SQL is not an efficient design.

Ishan

Tags: Database

Similar Questions

  • How to execute the sql statement in the file beats?

    I want to execute after the statement
    C:\ > sqlplus/nolog
    SQL > conn scott/tiger
    SQL > select * from tab;

    I know I can achieve it following test.bat and testdb.sql file
    test.bat is:
    sqlplus/nolog @testdb.sql

    TestDB.SQL is:
    Conn scott/tiger
    Select * from tab;

    Now I don't want to use the sql file, I want only use bat file, as follows:
    test.bat is:
    sqlplus/nolog
    Conn scott/tiger
    Select * from tab;

    When I run test.bat, I find only one sqlplus /nolog execute statement, do not execute other statements.
    (1) I want to know if there is a method to run the SQL file by fighting without a sql file? How to make it happen?
    (2) if I call the sql file, how to hide the password of user? Because I don't want other people to know scott password, if I use conn scott/tiger in testdb.sql, other person can see testdb.sql and the password. Is there a good way to avoid?

    Thank you!

    It works a bit different in Windows. Create a file is like this:

    (
      echo conn scott/tiger@orcl
      echo spool c:\temp\list.txt
      echo select sysdate from dual;
      echo spool off
      echo exit
    ) | sqlplus -s -l /nolog
    
  • How to execute the SQL statement in the Application Module

    Hi people
    I´d would like to know how I can execute a SQL statement like "remove user" in the Module to request... prepareSession method...
    I m using Jdev 10 with ADF Faces
    Thank you

    This is possible, but you should think twice about it.
    If this can be done with an EO/VO do in this way.
    If you can't do it with an EO/VO you can yourself the DB operation (ApplicationModule.getDBTransaction ()) and use a call of createStatement (...) do what you want.

    Timo

  • How to debug an application incident that occurs only within the executable and not developing?

    LabVIEW 2011

    Looking for ideas on how to debug an application that crashes only from within the executable.

    Is there something useful that this error report can be used to, thanks in advance.

    ####
    #Date: Tuesday, August 23, 2011 15:10:18
    #OSName: Windows 7 Enterprise
    #OSVers: 6.1
    #OSBuild: 7600
    #AppName: LabDAQ
    #Version: 11.0 32-bit
    #AppKind: AppLib
    #AppModDate: 23/08/2011 18:59 GMT
    Base address of #LabVIEW: 0 x 30000000

    23/08/2011 3:10:48.331 PM
    Crash 0 x 0: Crash taken to DENY
    File Unknown (0): Crash: Crash captured by DENYING
    Minidump ID: a1c0be18-ad05-4b09-b914-afe4a3073daf
    ExceptionCode: 0xC0000005± N
    0x3072C874 - lvrt + 0
    0x3072CC28 - lvrt + 0
    0x7C37FDB4 - MSVCR71 + 0
    0x77330DF7 - ntdll + 0
    0x772F9ED5 - ntdll + 0
    0x00000000 - + 0

    I sprinkle a button Dialogs in any code that I can see to what extent the code gets before it crashes.

  • How can I remove the 'State' that wants an installation package "status.msi" I do not have?

    This laptop does not accept even in SP3. It doesn't have enough RAM for Win7.   I got rid of bad bits with chkdsk.  Status tries to install all the time & I can't find how to remove it.

    Hello
    I've got SP3 now after 2-3 attempts.  (Just 'failed to install.")
    And for the status "the component you are trying to install is on a CD or another removable disk that is not available."
     
    "Insert the diskette in the State, and then click OK.   Use Source 1. "The next window"cannot find an installation package for the product status.  Again the installation again using a valid copy of the installation package "status.msi." "
     
    The link with Microsoft wasn't working, so I checked on Google and found this annoying file is a file of HP printer so I deleted the HP printer program, which got rid of the file.  It seems, I then have to re - install the program without checking the update box, I'll try it when I have the time.
    Thanks a lot for your help.
  • How do I know the partition that is moved within the storage space?

    I'm currently moving the partitions of a table to reclaim space and I do not transfer to another tablespace, in other words, I just move into the storage space.

    The tablespace contains one table.

    The most difficult part of putting them in the same tablespace is now, that I could not easily identify which partition to date is moved. When I created the script to move partitions, I've sorted them all first.

    I asked the DBA_SEGMENTS and learned the segment_type is TEMPORARY and that the size continues to change right away.

    The nom_segment is "37.75756073" and does not say clearly what partition is moved.

    I know that the '37' part. It's a the file_id. But what is this "75756073"? I checked the object_id and data_object_id from DBA_OBJECTS, but he did not show everything.

    I questioned the block_id from DBA_EXTENTS, but neither did - it show the nom_partition.

    Any other ideas?

    SQL > select nom_segment, segment_type, nom_partition, dba_segments bytes/1024/1024/1024 GB

    where nom_tablespace = 'P_SGSN_1_WEEK. '

    order by nom_partition;

    NOM_SEGMENT NOM_PARTITION SEGMENT_TYPE GB

    ------------------------- ------------------------------ ------------------ ----------

    PARTITION TABLE PS_SGSN_1_WEEK P_20131202 314.199219

    PARTITION TABLE PS_SGSN_1_WEEK P_20131209 324.589844

    PARTITION TABLE PS_SGSN_1_WEEK P_20131216 333.359375

    PARTITION TABLE PS_SGSN_1_WEEK P_20131223 320.097656

    PARTITION TABLE PS_SGSN_1_WEEK P_20131230 303.691406

    PARTITION TABLE PS_SGSN_1_WEEK P_20140106 297.34375

    PARTITION TABLE PS_SGSN_1_WEEK P_20140113 313.320313

    PARTITION TABLE PS_SGSN_1_WEEK P_20140120 321.875

    PARTITION TABLE PS_SGSN_1_WEEK P_20140127 334.453125

    PARTITION TABLE PS_SGSN_1_WEEK P_20140203 324.6875

    PARTITION TABLE PS_SGSN_1_WEEK P_20140210 300.15625

    NOM_SEGMENT NOM_PARTITION SEGMENT_TYPE GB

    ------------------------- ------------------------------ ------------------ ----------

    PARTITION TABLE PS_SGSN_1_WEEK P_20140217 295.332031

    PARTITION TABLE PS_SGSN_1_WEEK P_20140224 294.609375

    PARTITION TABLE PS_SGSN_1_WEEK P_20140303 311.933594

    PARTITION TABLE PS_SGSN_1_WEEK P_20140310 318.066406

    PARTITION TABLE PS_SGSN_1_WEEK P_20140317 314.335938

    37.75756073 TEMPORARY 265.996094

    17 selected lines.

    Our version of Oracle RDBMS is 11 GR 2

    Watch LAST_DDL_TIME to the USER_OBJECTS partition (the name of the table would be OBJECT_NAME and the name of the partition would be SUBOBJECT_NAME "PARTITION TABLE" would be the OBJECT_TYPE) to identify the last partition that has been moved.  Given that your script is the partition names ordered, you would know the next parttiion after it - such next partition would be one that is currently "moved".

    Hemant K Collette

  • How to run the function body that is stored in the variable string?

    Hello!

    Let's say we have a function body stored in the string variable, like this:

    ......

    ......

    var body: String = "public function display_message(kom:String):void {mx.controls.Alert.show (kom) ;};

    .....

    Here, I would like to do something with variable 'body' to run the code in this variable, is - it possible?

    ......

    ......

    With regard to the bars.

    d.Eval can do what you want. check it out at http://www.riaone.com/products/deval/index.html

  • How to execute a stored procedure that returns a cursor?

    How to execute a stored procedure that returns a cursor?

    Follow the code:

    CREATE OR REPLACE PROCEDURE stp_cashin_grupo
    (p_func in VARCHAR
    p_cod_grup in full
    p_des_grup in VARCHAR
    p_logi in VARCHAR
    p_curs_rset ON infoc.pck_cashin_grupo.curs_rset
    )
    IS
    BEGIN

    If p_func = "1" then
    OPEN FOR P_curs_rset
    Select
    cod_grup
    des_grup
    dat_manu_grup
    des_logi_manu
    of infoc.tbl_cashin_grupo
    order of des_grup;
    end if;
    END stp_cashin_grupo;


    and packaging:

    CREATE or REPLACE PACKAGE pck_cashin_grupo
    AS
    TYPE curs_rset IS REF CURSOR;
    END pck_cashin_grupo;

    My question is how to execute in sql plus?
    Stp_cashin_grupo EXEC ('1', 0, ", '465990', my doubt is how to move the cursor as return)


    Thank you

    It is described in the manual

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14357/CH5.htm#sthref1122

  • How to block a select statement for a table of the specified until validation line

    Hello

    How to block a SELECT statement for a specified row in a table until willingness to engage occure?

    My procedure is part of a Stock request and if a user (X) get stock 1 piece, another user must wait for the user (Y) complete his reportoire.

    So, let say my stock have 10 pencils.

    When the X user starts the Stock_PLS procedure, in table Stock, line (e.g. R1) that user X should work with it, must be lock up to what the commit / rollback will appear.

    procedure Stock_PLS...

    Start
    ..
    pencils: pencils-1 =;
    ..
    End

    Observation-> pencils: = 9;


    This means that is a user there, run SELECT * stock of the table where rows_id = R1, SELECTION should wait the Stock_PLS started by user X will be completed (with commit or rollback) and his SELECT should return the value 9.

    What I need, is that Oracle has something like LINE EXCLUSIVE TABLE LOCK, but in my situation the SELECT statement should be denied on the specified lines, until the end of the procedure.

    Kind regards
    Michael

    Hello
    You can achieve this using the update with the Select clause.
    You can write your select statement like this
    SELECT * from stock of the table where rows_id = R1 for update;

  • See all SQL statements that have been executed in a transaction active?

    When I ask transaction$ v, $session of v and v$ sql, all that I see is the SQL statement being executed in a transaction active.
    How can I view all of the SQL statements that were executed as part of an operation running since the beginning of this transaction?

    If you use database 11g, you can use bed > view and manage Transactions that shows all the steps of sql in transactions.

    KDSDBA
    OCP

  • How can I create a button that will execute some SQL such as UPDATE, DELETE ststements

    Hi all.
    I'm new on ADF.
    I start with this example from oracle
    [http://www.oracle.com/technology/obe/obe11jdev/ps1/ejb/ejb.html]

    My question is how can I make a button that executes sql statements like "set 'name' = last_name employees where employee_id = 111; updated"
    any hint will help you.
    Thank you

    If you are using JPA/EJB then you can write in your session bean method to access the EntityManager and using createNativeQuery to perform the update:
    http://download.Oracle.com/docs/CD/E17477_01/JavaEE/5/API/javax/persistence/EntityManager.html#createNativeQuery (java.lang.String)
    This method will be exposed in your ADF data control and you will be able to drag it to your page.

    If you use ADF BC then you can use the methods of service level AM:
    See 9.7 to 9.9 in the Fusion developer's Guide:
    http://download.Oracle.com/docs/CD/E15523_01/Web.1111/b31974/bcservices.htm#sm0206
    http://download.Oracle.com/docs/CD/E15523_01/Web.1111/b31974/bcadvgen.htm#BABEIFAI

  • Identify the SQL statements that are executed frequently

    I would like to identify SQL statements that are executed may times (e.g., > 1000 times) during an interval AWR.

    I am aware of coloring a SQL_ID with exec ('...') dbms_workload_repository.add_colored_sql; but then the SQL ID must be known.

    Is it also possible to do the same for the (not yet known) SQL statements that are executed > 1000 times? I think that the SQL statements that run very quickly (for example 1 s <) won't be captured automatically in a CWA even if those statements are frequently performed.

    Version 11.2.0.4 on SLES11

    Try this...

    fixed lines 155

    execs from collar to 999 999 999

    Col min_etime to 999,999.99

    Col max_etime to 999,999.99

    Col avg_etime to 999,999.999

    Col avg_lio to 999,999,999.9

    Col norm_stddev to 999,999.9999

    Col begin_interval_time to a30

    node of col to 99999

    break on plan_hash_value on startup_time skip 1

    Select * from)

    Select sql_id, sum (execs), min (avg_etime) min_etime, max (avg_etime) max_etime stddev_etime/min (avg_etime) norm_stddev

    de)

    Select sql_id, execs, plan_hash_value, avg_etime,

    StdDev (avg_etime) on stddev_etime (sql_id partition)

    de)

    Select sql_id, plan_hash_value,.

    Sum (NVL(executions_delta,0)) execs,

    (sum (elapsed_time_delta) /decode (sum (nvl(executions_delta,0)), 0.1, sum (executions_delta)) / 1000000) avg_etime

    -sum ((buffer_gets_delta/decode (nvl(buffer_gets_delta,0), 0.1, executions_delta))) avg_lio

    DBA_HIST_SQLSTAT s, DBA_HIST_SNAPSHOT SS

    where ss.snap_id = S.snap_id

    and ss.instance_number = S.instance_number

    and executions_delta > 0

    Group of sql_id, plan_hash_value

    )

    )

    Group of sql_id, stddev_etime

    )

    where norm_stddev > nvl (to_number('&min_stddev'), 2)

    and max_etime > nvl (to_number('&min_etime'),.1)

    order of norm_stddev

    /

  • How to execute dynamically generated using GR 11, 2 SQL statements?

    Hello

    I would like to know if it is possible to do what the following statement which is intended :
    select * from (select replace('select empno from emp',
                                 '',
                                 '') from dual);
    in other words, is it possible to dynamically generate and execute a select statement in a from clause?

    Thank you for your help,

    John

    Published by: 440bx 16 July 2010 15:57 modified 'create' to 'generate' to the subject

    Like many I know no. in SQL. Results of your query in the FROM clause will not be transformed as another query, but just a litral value and your outer query returns this value as "select empno from emp".

    But you can use dynamic sql statements in PL/SQL using EXECUTE IMMEDIATE or DBMS_SQL.

    Something like that.

    DECLARE
     dynamic_from_clause VARCHAR2(4000) := 'select empno from emp';
     vReturnVal NUMBER;
    BEGIN
      EXECUTE IMMEDIATE 'SELECT * FROM ('||dynamic_from_clause||')' into vReturnVal ;
    END;
    /
    

    Just write memory have not tested it.

  • How to run grid sql statements

    Hello

    I would like to run some of the grid control sql statements as tablespace freespace check.

    Grid options could there be to execute the sql statement?

    If so, how to set up the output of the sql for E-mail

    Please I need your suggestion to proceed.

    Version of the grid: 10.2.0.5.0
    Platform: Sun

    Thank you.

    Hello

    no need to run the sql statement of the grid, instead of that you can configure the threshold values.

    for example, if your tablespace capacity 85% complete and then he will send you the email alert that you configured in notifications.

    you will find on the home page - bottom of the page - > manage settings...

    check http://download.oracle.com/docs/cd/B19306_01/server.102/b14196/montune001.htm#CACCIHAB

    http://download.Oracle.com/docs/CD/B19306_01/EM.102/b40002/notification.htm#sthref995

    Thank you

  • How to plan the CREATE statement (not MERGER-edit) without start/end of PL/SQL

    I have dozens of instructions MERGE (also Create and Drop statements) that I want to run every morning.
    I can do without this help:
    1. the windows task scheduler (I don't like having to change my password) or relying on my machine to run at midnight
    2 convert the "Execute Immediate" instructions statements within a PL/SQL block?

    Ideally, I would like to put in place a procedure, but can't seem to find away around doing without the begin/end blocks.

    We are running Oracle 10 g.

    Thank you
    Jason

    Published by: Jason_S on Sep 2, 2011 10:42

    Jason:

    It looks like a GTT would be ideal for this. Non-recurring Yes:

    CREATE GLOBAL TEMPORARY TABLE f_pi_sequ_list (
      pi_seq   )
      On commit delete rows;
    

    Then, your script would become:

    INSERT INTO f_pi_sequ_list
    SELECT pp_pi_sequ AS pi_sequ
    FROM f_pat_present
    WHERE pp_sequ >= &min_pp_sequ AND
          pp_sequ <= &max_pp_sequ
    GROUP BY pp_pi_sequ;
    
    MERGE INTO f_patient_index dst
    USING  (SELECT * FROM f_patient_index@REDC
            WHERE pi_sequ IN (SELECT pi_sequ FROM f_pi_sequ_list)) src
    ON     (DST.PI_SEQU = SRC.PI_SEQU)
    WHEN MATCHED THEN UPDATE
    SET     big long list
    WHEN NOT MATCHED THEN
    INSERT big long list
    VALUES big long list;
    
    COMMIT;
    

    I doubt that the indexes on the table of the single column contributes everything, so you could probably do without it.

    After validation, the TWG will be empty, so the next time you need to use it, simply to make the insertion. If you will use the same list of values in the other queries as part of your script, change delete lines to preserve the lines, then the data will remain as long your session is active, or that you explicitly remove the lines.

    John

Maybe you are looking for

  • Unable to encrypt USB / El Capitan

    Using a Macbook Air running El Capitan 10.11.4... (Sorry if this is the wrong forum, but I've never understood how to navigate to the right place n communities Support from Apple). I tried (for literally a few hours) to find how pw - protect / encryp

  • IM sending questions

    I am 100% connected, no problems with my connection wi - fi or anything like that. Skype has always run beautifully so far.Whenever I try is send an instant message to a friend, acts of Skype as nobody is online and does not send the message. I get t

  • HP Pavilion dv7 Notebook PC: Windows Media Player replacement

    I currently use Windows Media Player to play CDs, DVDs, BlueRay discs and for monitoring emissions of air with my unencrypted, i.e. without a cable box, to view TV shows, because I have a TV card installed by HP, and a digital antenna I bought at HP

  • I lost all my pictures and music on hard drive

    my pc did not start after the installation of the printer without disc, I did a complete system restore (I think), the pc works now, but I lost all photos of doc., music please help I really need thank you back photos

  • How to organize files to display in chronological order

    I'm not having problems, but I would like to have documents displayed in the order that they were created.  Is this possible?