Select table_name dynamic pl/sql variable - possible?

Hello

With the help of 11.2.0.3

Select count (*)

in v_cnt

products

example, but when we do not know the name of the table until the runtime, for example table pl/sql package is their < sysdate > produits_

Is it possible to use sql dyanamic for this instructions below does not work

Select count (*)

in v_cnt

of < dyanmic_table_name >

If so, how?

Thank you

Hello

try something like this

create or replace function fn_count_rows ( table_in in varchar ) return number
is
number_of_rows number;
begin
  execute immediate 'select count(*) from ' || table_in into number_of_rows;
  return number_of_rows;
end;
/

concerning
Kay

Tags: Database

Similar Questions

  • ORA-00942 on sys when SELECT table_name FROM all_tables;  11rg2 (answered)

    I run SQLPLUS on windows and use sqlplus.
    Conn sys as sysdba. Fine
    Then, I want to see the tables under sysdba
    I create the table and I can do SELECT * from table. SQL watch me release.
    But I can't see tables
    SELECT table_name FROM user_tables;
    SELECT table_name FROM all_tables;
    SELECT table_name FROM dba_tables;
    SELECT * from user_objects where type_objet = "TABLE";

    SQLPLUS:ORA - 00942: table or view does not exist.

    How to fix it?
    I created earlier DB and could do that, but I want to repair this database.

    And he had problems with db mynewdb1, may be corrupt

    recover database until cancel using backup controlfile;
    ORA - 279 marked during: ALTER DATABASE RECOVER database until cancel using backup controlfile...
    ALTER DATABASE RECOVER CONTINUE DEFAULT
    C:\APP\STR\FLASH_RECOVERY_AREA\MYNEWDB1\ARCHIVELOG\2013_05_10\O1_MF_1_1_%U_ media recovery log. ARC
    Friday 10 May 21:06:30 2013
    Errors with log C:\APP\STR\FLASH_RECOVERY_AREA\MYNEWDB1\ARCHIVELOG\2013_05_10\O1_MF_1_1_%U_. ARC
    Errors in the C:\APP\STR\diag\rdbms\mynewdb1\mynewdb1\trace\mynewdb1_pr00_9920.trc file:
    ORA-00308: cannot open archived log ' C:\APP\STR\FLASH_RECOVERY_AREA\MYNEWDB1\ARCHIVELOG\2013_05_10\O1_MF_1_1_%U_. ARC'
    ORA-27041: could not open the file
    04002 - OSD: could not open the file
    S/O-error: (OS 2) the system cannot find the file specified.
    ORA - 308 marked during: ALTER DATABASE RECOVER CONTINUE DEFAULT...





    CREATE CONTROLFILE REUSE DATABASE RESETLOGS MYNEWDB1
    WARNING: Temporary Tablespace default not specified in the CREATE DATABASE command
    Default temporary tablespace will be necessary for a locally managed database in future release
    Errors in the C:\APP\STR\diag\rdbms\mynewdb1\mynewdb1\trace\mynewdb1_ora_8588.trc file:
    ORA-01565: error to identify the file ' % ORACLE_HOME%\DATABASE\DBS1%ORACLE_SID%. ORA'
    ORA-27041: could not open the file
    04002 - OSD: could not open the file
    S/O-error: (OS 2) the system cannot find the file specified.
    ORA-1503 scored at the course: CREATE CONTROLFILE REUSE DATABASE RESETLOGS MYNEWDB1...

    Published by: 1005307 on 10.05.2013 18:08

    Hello

    Welcome to the forums!

    What you showed us, I guess that you have created the database manually using the CREATE DATABASE command?

    If so, did you run CATPROC.sql and CATALOG.sql correctly? It seems that your problem is related to these scripts, because they are responsible for creating the tables and the data dictionary views.

    Have you run them with SYS schema?

  • Reading the value of a PL/SQL variable

    Hello

    I have a requirement where I need to read the contents of a pl/sql variable and then write in an operating system file. a .sql or .txt file.

    What can I do with it?

    Any help will be much appreciated.

    Kind regards
    SID

    Hello

    Example script e.r.y

    DECLARE
    v_output UTL_FILE.FILE_TYPE;
    CURSOR c1
    IS
    select cust_cod,mobile_no
    from main_master
    where rownum <11;
    BEGI
    v_output:=UTL_FILE.FOPEN('/rman/report/textfiles/','OUTPUT_DATA.TXT','W');
    /**You should have write permission to write onto direcotry /rman/report/textfiles ***/
    FOR i IN c1
          LOOP
    UTL_FILE.PUT_LINE(v_output,i.cust_cod||'  '||i.mobile_no);
    END LOOP;
    UTL_FILE.FCLOSE(v_output);
    END;
    

    Kind regards
    Claudy

  • nesting queries on multiple sql files - possible?

    Hello

    I was wondering if the following would be possible, and if so what the syntax in sqlplus?

    Imagine I have a query that generates a table of data output. I can then refer to it and affix analytical functions on this one in a separate sql file?

    For example if I have the query:

    AB.sql
    select count (*)
    from (select sysdate from dual)
    I could this split into two files sql A and B?

    A.SQL
    select sysdate from dual
    B.SQL
    select count (*) from @C:\A.sql
    the result of the execution of B.sql would be 1.

    for now I really wonder if this is doable on a conceptual level, anyone know?

    Thank you

    Jon

    Yes, on the conceptual level, it is possible.

    cat a.sql
    select count (*)
    from (
    @b.sql
    )
    ;
    
    cat b.sql
    select sysdate from dual
    sqlplus scott
    
    SQL*Plus: Release 11.2.0.1.0 Production on Fri Nov 12 13:13:58 2010
    
    Copyright (c) 1982, 2009, Oracle.  All rights reserved.
    
    Enter password:
    
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    
    SQL> set echo on
    SQL> @a.sql
    SQL> select count (*)
      2  from (
      3  @b.sql
      3  select sysdate from dual
      4  )
      5  ;
    
      COUNT(*)
    ----------
             1
    

    Best regards

    Maxim

  • How to assign the pl/sql variable to a variable of the page element?

    I want to select count (*) in the emp table.

    assign this count (*) total to a pl/sql variable.

    How can I assign this varialbe pl/sql variable of page element?

    : p2_test = pl_total;

    Thank you.

    Good afternoon

    Try this:

    1. create a process Page:

    Declare
    pl_total number;
    Begin
    select count(*)
    into pl_total
    from emp_table;
    :P2_test := pl_total;
    End;

    Or a simpler approach:


    Begin
    select count(1)
    into :P2_test
    from emp_table;
    End;

    If you use count (1) rather that count (*), you do the inventory column 1 and not the entire file. Oracle then reads just column 1 instead of the whole of the record, speed up your query, if the table can have a large number of columns AND a lot of files.

    Good luck
    Don.

    You can reward this answer by marking as being useful or correct :)

  • Very new to photoshop, I try to make changes to a photo and set up as a dynamic object, but after the selection of dynamic object, the grid appears and my photo dissppears

    Very new to photoshop, I try to make changes to a photo and set up as a dynamic object, but after the selection of dynamic object, the grid appears and my photo dissppears

    Well, something's wrong with Photoshop. Try to close Photoshop, and then press Command + Option + shift as you restart Photoshop. You will be asked to clear the Photoshop preferences. ATTENTION: you will lose all current preferences.

  • How to test different Select into a PL/SQL block?

    Hello

    I'm relatively new to PL/SQL and I'm doing several int selects only one PL/SQL block. I am faced with the fact that if a single select statement returns no data, I have to go to the when exception DATA_NOT_FOUND.

    Or, I would test selects different.

    In an authentication script, I'm looking for a table for a USER ID (USERID) and an ID application, to check if a user is registered under this username for this APPLICATION.

    There are different possibilities: 4 possibilities:
    -Existing USER name or do not exist and
    -Aplication ID found or not found for this particular USER ID.

    I would test teas 4 possibilities to obtain the status of this user do regardin this application.

    The problem is that if a select returns no rows, I'll not found exception data.
    In the example below you can see that if no line is returned, with the exception
    DECLARE
    P_USERID VARCHAR2(400) DEFAULT NULL;
    P_APPLICATION_ID NUMBER DEFAULT NULL;
    P_REGISTERED VARCHAR2(400) DEFAULT NULL;
    BEGIN
    SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES
    WHERE  USERID = :P39_USERID AND APPLICATION_ID = :APP_ID ;
    :P39_TYPE_UTILISATEUR := 'USER_REGISTERED';
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    :P39_TYPE_UTILISATEUR := 'USER_NOT_FOUND';
    END;
    I would like to first of all make this statement:
    SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES
    WHERE  USERID = :P39_USERID 
    Do this if the user is found:
    SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES
    WHERE  USERID = :P39_USERID AND APPLICATION_ID = :APP_ID ;
    etc...

    Basically, I don't want to go to the not found exception before you have tested the 4 possibilities.

    Do you have a suggestion?

    Thank you very much for your help!

    Christian

    If you I had to check several conditions, this is how I would do:

    DECLARE
      P_USERID         VARCHAR2(400) DEFAULT NULL;
      P_APPLICATION_ID NUMBER DEFAULT NULL;
      P_REGISTERED     VARCHAR2(400) DEFAULT NULL;
    BEGIN
     SELECT USERID
         , MAX(DECODE(application_id, :APP_ID, :APP_ID)) app_id_valid
      INTO P_USERID
         , P_APPLICATION_ID
      FROM ACL_EMPLOYEES
     WHERE USERID = :P39_USERID
     GROUP BY USERID
    
     IF P_APPLICATION_ID IS NULL
     THEN
       :P39_TYPE_UTILISATEUR := 'NOT REGISTERED TO APPLICATION_ID';
     ELSE
       :P39_TYPE_UTILISATEUR := 'USER_REGISTERED';
     END IF;
    EXCEPTION
      WHEN NO_DATA_FOUND
      THEN
        :P39_TYPE_UTILISATEUR := 'USER_NOT_FOUND';
    END;
    /
    

    not tested

    C.

  • How to read a file of all the text in a pl/sql variable?

    Hi, I need to read an entire text file - which actually contains an e-mail message from a system of content management - in a variable in a pl/sql package, in order to insert the database information and then send the email. I want to read the whole of a sudden text file, no not one line at a time. Shoud I use Utl_File.Get_Raw or is there a more appropriate to do this?

    How to read a file of all the text in a pl/sql variable?

     ...
    your_clob_variable := dbms_xslprocessor.read2clob('YOUR_DIRECTORY','YOUR_FILE');
    ....
    
  • After a SELECT INTO, the use of the result as a parameter to another SQL variable?

    Hello world

    My apologies for these basic questions, but I need your help in order to run the report in STATSPACK (spreport.sql) in a NON-interactive manner.

    To do this, I need 3 parameters:

    1. begin_snap
    2. end_snap
    3. report_name

    I have a version of the report named spreportBH.sql. This sql receives 3 parameters and generates the report success.

    SQL > @spreportBH.sql 923 1111 /u01/BHB/test4.txt

    For this example begin_snap=923, end_snap=1111 and report_name is /u01/BHB/test4.txt

    My problem is that the snapid must be calculated based on the date.

    To achieve this goal, I can query the table STATS$ SNAPSHOT.

    For example, this query gives me the 923:

    Select min (snap_id)

    de PERFSTAT . STATS$ SNAPSHOT

    snap_time >= TO_DATE ('12-06-2014','dd-mm-YYYY');


    I know that I can put the value in a variable. For this, I'm doing:


    sqlplus "virtue sysdba" s < <!   1 > > ${fichier_de_sortie} 2 > > ${error_file}

    DECLARE

    firstSnapId NUMBER;

    BEGIN

    Select min (snap_id) INTO firstSnapId

    of PERFSTAT. STATS\$ SNAPSHOT

    where snap_time > = to_date ('12-06-2014', ' dd-mm-YYYY');

    END;

    /

    !


    How can I use firstSnapId to call @spreportBH.sql?

    I'd appreciate any help that can give me.

    Thank you d ' attribute

    Bety



    Hi, Bety,

    So, you want to call a script in SQL * more.  I'm not suggesting using PL/SQL use SQL * Plus Substitution Variable instead.

    -The following command of the COLUMN said that everything which appears in a column called

    -firstSnapIdCol will also go in a variable of substtitution called firstSnapId

    COLUMN firstSnapIdCol new_value by firstSnapId

    Select min (snap_id) AS firstSnapIdCol  

    of PERFSTAT. STATS$ SNAPSHOT

    where snap_time > = to_date (6 December 2014 ", 'dd-mm-YYYY');

    -Now that firstSnapId has a value, we can use it like this:

    @spreportBH.sql & firstSnapID 1111 /u01/BHB/test14.txt

  • Oracle PL/SQL Web service - dynamic parameters... possible?

    Oracle 11.2.0.3 - newbie on web services!

    Currently we have a pl/sql web service takes 2 static parameters and return a response of varchar2.

    Asked me today if it is possible for a web service in a dynamic set of parameters and return a set of results. It's as if I have to pass the web service a table with two columns and return an array from a column.

    For example:
                        Input                          Output
              1 2                             3
              3 4                             7 
              5 6                            11
    of course in XML output. Is it possible?

    p.s. I posted this in OC4J also - no response so the re-post!

    Parameters related to the procedures. Web services require XML messages.

    Where are the settings? You cannot pass a dynamic number of parameters in a procedure, but you can pass a structured as a parameter type that can contain multiple values, either a table/collection type or document XML itself.

    All package values in the XML file and pass it to the web service.

    If this isn't answering your question, please post more information, with some sample data and code. Read the FAQ: {message identifier: = 9360002}

  • Problem with the selection list dynamic LOV using bind variables

    I have the following SQL to fill a selection list:

    Select d, ch from
    (
    Select ft. FAMT_NAME d, pi. R FAM_ID_T of FAMILY_TRA ft
    Join the ck list
    on ck.family = ft.famt_name and ck.newseq in (: NEWSEQ_QUERY_SQL)
    )

    Where NEWSEQ_QUERY_SQL is a part of the application that is defined by a calculation of page and essentially returns a list of values NEWSEQ based on some parameters of the user query. For example:

    Select distinct (ck.newseq) in the ck list where rownum < 20

    The query above works fine with SQL Developer and returns two columns needed (display_value, return_value)

    However, it returns no line, when it is used to fill the LOV to a selection list.

    If I replace the: NEWSEQ_QUERY_SQL with a list of NEWSEQ hard-coded, it works:

    Select d, ch from to)
    Select ft. FAMT_NAME d, pi. FAM_ID_T r
    of FAMILY_TRA ft join checklist ck on (ck.family = ft.famt_name and ck.newseq in ('K0242900', 'K0217200'))
    ) ;

    I can even replace: NEWSEQ_QUERY_SQL with hard-coded SQL and it works:

    Select d, ch from
    (
    Select ft. FAMT_NAME d, pi. R FAM_ID_T of FAMILY_TRA ft
    Join the ck list
    on (ck.family = ft.famt_name and ck.newseq in (select ck.newseq from the list ck where rownum < 20))
    )

    But if there is a connection variable (: NEWSEQ_QUERY_SQL), it doesn't.

    Selection lists are driving me crazy! They seem incredibly capricious.

    Hello:

    You cannot link a "sql statement" that bind the value you're trying to do.
    P2_FAMILY_LIST must be the SQL statement you executed for the LOV. Something like

    select d, r from
    (
    select ft.FAMT_NAME d, ft.FAM_ID_T r from FAMILY_TRA ft
    join checklist ck
    on (ck.family = ft.famt_name and ck.newseq in (select ck.newseq from checklist ck where rownum < 20))
    )
    

    CITY

  • Limits of dynamic Calc Manager Variables

    Hello, is it possible to specify a dynamic range in the "limits" of a variable of Manager calc?  I want to do is limit a RTP for the period dimension so that a user to select from a range of forecast periods.  periods are a range of forecasts of starts by a planned start-up period and traverse December i.e. & fcstMnth:Dec.  I tried to use the range (& fcstMnth:Dec) in the specification of limits, but that has not worked.

    Thank you

    The structure of the period is standard. Periods of roll up to quarters and full year.  I see what went well, my period subvar has been the last period in a quarter, apparently when @irsiblings is used in "limits", it will not cross parents level members, in my case the quarter.  that is, if the period subvar has been set to Jan, the function returns only Jan, Feb, Mar to RTP.  I used @list(&fcstMnth:Dec) instead and it worked correctly.  Thanks for your help

  • Problem with PL/SQL variables...

    Hi, I am fairly new to this, so apologies if this is a simple question.

    I have a text field on my page (ENTITY_ACC_NO), and I'm putting a pl/sql block on it to fill with a conditional piece of treatment based on the value of another field (ENTITY_SELECT). (Its actually a drop-down list)


    So on the source of the article, I updated the source type the body of the pl/sql function with the following code piece...

    IF: ENTITY_SELECT = '%' THEN

    : ENTITY_ACC_NO: = ";

    ON THE OTHER

    Select account_no in: entity_acc_no of the entity where entity_id =: entity_select;

    END IF;

    The problem is that it does nothing... Firstly, I correctly use variables? I read somewhere that you should use the function of V, but it also seems like you use this for stored procedures, rather than a simple pl/sql.

    Either way, im actually trying to work around the error as the drop-down list has '%' in it for another database query text, and I use it here through its primary key to retrieve other information about this...

    Thank you very much

    Richard

    Source of the element is used when rendering a page - looks like you can expect as things change when a selection list option is specified.

    Discover the use of dynamic actions

    http://www.grassroots-Oracle.com/2013/10/Apex-101-dynamic-actions.html

    The other thing that I can see is the page elements, you specify is not a page number of prefix, which is worth questioning - you specify the name and why you use the conventional notation P1_ITEM_NAME?

  • Dynamic PL SQL query

    Hello

    I want to run and store the results of a dynamic sql query in a strored procedure.

    I get the following variables of the user running: v_column_names, v_table_name, v_col, v_value

    The query will be like:

    v_query: = 'SELECT'. v_column_names | ' A ' | v_table_name | ' WHERE ' | v_col |' = ' | v_value;

    for example v_column_names: = 'ACCOUNT_NUM, SYSTEM_ID, ENTITY_ID ';

    v_table_name: = 'ACCOUNT '.

    v_col: = 'COUNTRY_CODE ';

    v_value: = "USA";

    Here is what I tried

    DECLARE

    v_column_names VARCHAR (200): = 'ENTITY_ID, SYSTEM_ID, ACCOUNT_NUM;

    v_table_name VARCHAR (200): = 'ACCOUNT '.

    v_col VARCHAR (200): = 'COUNTRY_CODE ';

    v_value VARCHAR (200): = "'USA"';

    TYPE column_record () IS RENDERING

    VARCHAR2 (200) C1: = null;

    C2 VARCHAR2 (200): = null;

    C3 VARCHAR2 (200): = null

    );

    TYPE st_table IS TABLE OF column_record INDEX DIRECTORY.

    pk_table st_table;

    NUMBER of v1: = 1;

    BEGIN

    v_select: = 'SELECT'. v_column_names | ' A ' | v_table_name | ' WHERE ' | v_col |' = ' | v_value;

    EXECUTE IMMEDIATE v_select COLLECT LOOSE pk_table.

    I'm IN 1.pk_table.count LOOP

    DBMS_OUTPUT. Put_line (pk_table (v1). (C1);

    DBMS_OUTPUT. Put_line (pk_table (v1). (C2);

    DBMS_OUTPUT. Put_line (pk_table (v1). (C3);

    v1: = v1 + 1;

    END LOOP;

    END;

    The number of column names in v_column_names is dynamic, so I need a way to store the results and then manipulate them.

    I look forward to your reply.

    EDIT: The real question:

    1. in the settings I have pass the table name and the value of the primary key of the row I want to delete.

    2. He then checks if this line is referenced anywhere, removes the reference, and then deletes the current line. This can go, until all the rows that are referenced are removed.

    The above code, I have provided a small part of the largest of stored procedure.

    Thank you all, I found the tips very helpful. I found a solution to my problem:

    Oracle - how to build queries DELETE in PL/SQL, based on the tables of the FK relations? -Stack overflow

    It generates all removal requests to remove a specific line.  Not what I wanted, but this does not solve my problem.

    The reason why is that I discovered that we do not use the ON DELETE CASCADE that we don't remove a record accidentally, I know we have an option to restore, but it is just in case something goes wrong.

  • Get the "selected lines" value after sql custom query in the database adapter

    We execute a custom query in a database adapter. With other technologies (JDBC, etc.) the result of a query produces not only a game but the number of lines selected results. For example, the output of the script of Oracle SQL Developer will display something like:

    9999 selected lines

    at the end of the output of the script.

    I would like to obtain this value for a BPEL process. Of course, I could run a 2nd interview whose where clause is identical to the first, but select count (*) instead. However, it is not only ineffective but (in rare circumstances in an active database) could be the problem.

    It is not obvious to the novice BPEL how to get the selected value and the result set row in an Invoke. Is this possible?

    Maybe it's not the only solution - but this is how I did in the past.

    After step to invoke the adapter, use a step of the having-right/copy to fill a variable of integer type BPEL using the xpath count function...






    That should affect the number of records returned by the query.

    I hope this helps.

    Rod.

    Published by: Tunnels of Rod on December 15, 2009 13:16

Maybe you are looking for

  • Numbers: Count the number of times that a country occurs in the list

    A bit of history... I use version numbers 3.1 (OS X El Capitan 10.11.3) I have a list of countries of origin of the students in my school. I would like to have a form of analysis of the how many times a country occurs in the list.  IE: Australia 13,

  • Bug when printing unicode

    I try to print some unicode characters. The browser fine poster, but what impression he show some square as when unicode is not found. For example, try http://getbootstrap.com/components/. Unicode is well displayed in the browser, but when I print (w

  • How change/deaktivate/reset HDD - password on Portege M400?

    Hello does anyone know how to change or deaktivate KNOWN HDD - password a Portege M400? Once again: I know the password, but I get bored typing every start. Greetings M400User

  • How to activate the HDMI on Satellite P300-24Z?

    Hello Can someone tell me how the HDMI Port get activated? I tried everything: different cable; another TV; latest ATI CCC, Windows Vista, Windows 7, but not matter what I do it no picture. In the CCC port HDMI is not yet displayed. With HDMI output,

  • Cannot connect with 100 IGC

    I am trying to establish an ethernet connection from a windows to a SRS 100 CIG machine.  It does not appear when I try to set it up on MAX.  Should I have the real time module?  The machine and the IGC are on the same subnet.