Passing table name and columns name as parameters to procedure

i need a procedure that take table name and column names as parameters .
it should display all values in those columns
like
if i execute procedure p ( t1,c1,c2)
it should display c1,c2 values in t1 table
if i execute procedure p ( t1, c1,c2,c3)
it should display c1,c2,c3 values in t1 tables
no of column parameters changes

See if this helps...
First, read the manual on collections.
Second, define your expected results. You want to output the results to the screen? You cannot perform a 'select' in PL/SQL. You will have to select your output into another collection, then loop through that.
Finally, I am curious why this is necessary versus performing a regular query.
Take a look at this incomplete code.
create or replace
package dave_pac
IS
TYPE col_name_list IS VARRAY(20) OF VARCHAR2(30);
PROCEDURE SFA_TAB_COL1
(p_tname  IN    VARCHAR2
,p_cnames IN    col_name_list);
END;
create or replace
package  body dave_pac
IS
PROCEDURE SFA_TAB_COL1
(P_tname  IN varchar2
,p_cnames in col_name_list)
IS
l_stmt long;
l_rc number;
begin
l_stmt :='select '||p_cnames(1);
for i in 2..p_cnames.count
loop
l_stmt :=l_stmt||' , '||p_cnames(i);
end loop;
l_stmt:= l_stmt||' from '|| p_tname ;
execute immediate l_stmt;
end ;
END dave_pac;

Similar Messages

  • Query to find out the table name and column name..

    Hi Experts,
    I have an Oracle DB in which has more than 50 tables and 100,000 records. I want to get the record which contains *"ITxtVarValue references a non existing text"* the text.
    Is there any query there to find out the table name and column name of this particular record where it reside?
    Please help. Any help will be rewarded.
    Thanks,
    G

    Using this forum's search function, I found a thread that should give you an idea: How to find out a tablename
    C.

  • Table names and column names defined by other languages, not English.

    Hi, everyone.
    I am wondering if there are any possible problems or any inconvenience
    when I define table names and column names by Japanese, not English.
    Currently, we are using SQL server 2000 as a db and windows as a operating
    system. In the near future, we have the plan to change the database software
    and operating system to "Oracle 10g" and "Linux O/S".
    I have not experienced the oracle database, which has table names and column
    names defined by other languages, not English.
    Personally, I would like to use English as table names and column names.
    In this case, I might have to provide appropriate reasons.
    Are there any possible problems or any "inconvenience" in terms of
    system maintenance, development, or something else ?
    What could be pros and cons in this case?
    Thanks in advance.
    Have a nice day.
    Best Regards.
    Ho.

    First you need to make sure your database has character set that support Japanese.
    Choosing a Character Set
    http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14225/ch2charset.htm#i1007681
    The main "inconvenience" you will have is if the client doesn't support Japanese or unicode, it will have trouble to access the table.
    And say in future after the application been developed, you want to implement the schema in some English environment, you will have hard time to do it.
    My point is English tablename and column names doesn't prevent you use it in Japanese environment and save Japanese data but not vice-versa. Hope you understand.

  • Dict View name and column names

    Hi,
    Oracle 11.2.0.1
    Windows XP
    I wish to get the output of all the dictionary views with their name and column names something like this :
    VIEW NAME
    Name                                      Null?    Type
    VIEW NAME
    Name                                      Null?    Type
    ...Please tell me how do I get the above output for all the dict view from dict table.
    Thanks.

    Step 1:
    set serveroutput on;
    set feed off;
    set head off;
    set pages 200;
    spool dict.sql;
    declare
    tn varchar2(50);
    cursor c is select table_name from dict order by table_name;
    begin
    open c;
    loop
    fetch c into tn;
    dbms_output.put_line('begin');
    dbms_output.put_line('dbms_output.put_line(' ||chr(39) || tn ||chr(39) ||');');
    dbms_output.put_line('end;');
    dbms_output.put_line('/');
    dbms_output.put_line('desc ' || tn || ';');
    exit when c%NOTFOUND;
    end loop;
    close c;
    end;
    Step 2:
    Just edit dict.sql to remove top and bottom lines.
    spool dictcols.txt
    @dict.sql;
    spool off;
    But, this is not a good way to obtain your desired output. I am sure, other members can do it very smartly and efficiently.
    Regards
    Girish Sharma

  • Case sensitive table names and column names in 8i or 9i databases

    Hi everybody,
    I've got a couple of business-side colleagues who insist that Oracle table and column names are case sensitive. That is, there is a setting in the set up of a database that lets you pick if table and column names are case sensitive. For example, this would mean that there could be a table named EMP in a given schema schema plus a table named emp in that same schema.
    Can this be true? I'd be surprised of course, but I've been surprised before.
    Thanks for any direction.
    -- Bill Loggins

    You can do it, but I would avoid it like the plague.
    SQL> create table "a" (b date);
    Table created.
    SQL> create table "A" (b date);
    Table created.
    I think I would refuse to work on a database where this has been used !

  • Policy name and column name inside a policy function

    I have the following function associated with a policy in the employee table for SSN and SALARY columns
    FUNCTION empid_policy_fn (object_schema IN VARCHAR2, object_name VARCHAR2)
    end;
    When the policy fires, the schema name and the name of the table are passed onto this function which we can use inside this function but is there a way to get the policy name and the column name which invokes this function?. The problem here is, I'm using same function (common) for multiple policies in different tables and that's why I need to get these details.
    Thanks
    -Krishnamurthy

    Inside your policy function you can query V$VPD_POLICY along with V$SESSION, V$SQL and USER_SEC_RELEVANT_COLS
    to get the fired policy name and column_names.
    Something like
    SELECT v.POLICY, .........
                   FROM v$session ss, v$sql s, v$vpd_policy v
                  WHERE ss.SID = (SELECT SID
                                    FROM v$mystat
                                   WHERE ROWNUM = 1)
                    AND s.address = ss.sql_address
                    AND s.address = v.paraddr
                    AND s.hash_value = v.sql_hash
                    AND s.child_number = 0HTH

  • Table Name and Column name for Product Family Field under the Product Famil

    Hi,
    Please help me finding the table name and the column name for the 'Product Family' field and the 'Item' field under the Product families form. The navigation to this form is as follows:
    Material Planner Responsibility -> Setup -> Product Family
    Please help.
    Thanks,
    KM

    2 months ago, you asked a very similar question... and Markus gave you a good answer. His 2-months old answer still applies here.
    I recommend that you read it a again at Table name for backorder qty on sales order.
    When you have read his answer, please close both threads.

  • Restriction for tag name and column name

    It seems that the XML tag name has to be the same as the
    corresponging column name when using xmlgen.insertXML. Is there
    any plan to relax this restriction?
    null

    Yes, tag names have to be the same as the corresponding column
    names. That is the how we can figure out which tag/element
    should be loaded into which column. This seems to be the simples
    and the cleanest way of mapping tags to columns. Nevertheless, we
    are open to suggestions.
    Also, keep in mind that you can use XSLT to do all sorts of
    transformation (including tag name transformations) to your XML
    document, before inserting it into the database. This might
    solve your problem.
    B Lou (guest) wrote:
    : It seems that the XML tag name has to be the same as the
    : corresponging column name when using xmlgen.insertXML. Is there
    : any plan to relax this restriction?
    Oracle Technology Network
    http://technet.oracle.com
    null

  • Running a query in which table name and column name are passed as arguments

    Hello,
    I have a pl/sql code in which table_name and column_name are defined as variables.
    I want to run a sql query like update table_name set column_name = <value> where id='xyz';
    How can I achieve this?
    Thanks in advance.
    Regards.

    GHD wrote:
    DECLARE
    v_table_name VARCHAR2(50) := 'employees';
    v_column_name VARCHAR2(50) := 'first_name';
    V_SQL         VARCHAR2(1000);
    BEGIN
    V_SQL := 'UPDATE '||v_table_name||' SET '||v_column_name||'= ''Ray'''||'WHERE EMPLOYEE_ID = 101';
    EXECUTE IMMEDIATE v_sql;
    END;Hope it will be helpful.Yes quite. (and the following applies to ALL responses thus far)
    It helps in reducing performance.
    It helps in fragmenting the shared pool.
    It helps in causing ORA-04031 unable to allocate %s bytes of shared memory errors.
    It is a brilliant example... OF HOW NOT TO WRITE ORACLE CODE.

  • Help needed in making table name and column name dynamic

    please check the below query? in the below message
    Message was edited by:
    460425
    Message was edited by:
    460425

    thanks Dmytro,
    below is the script i was looking for it got it..any way thanks.
    just need to replace dbms_output.put_line with utl_file.put_line
    to put the code on server directory.
    and execute as and when required.
    Reg.
    AAK
    CREATE OR REPLACE PROCEDURE p_ad_log
    IS
         CURSOR tbl_cursor IS
              SELECT table_name FROM user_tables WHERE table_name IN('EMP','EMP1') ;
         CURSOR col_cursor( cp_table_name varchar2) IS
              SELECT column_name FROM user_tab_columns WHERE table_name=cp_table_name;
         --v_file_handle      utl_file.file_type;
         --v_file_dir          varchar2(30)      :=     'DIRECTORY PATH'     ';
         --v_file_name     varchar2(30)       :=       'AD_TRIGGER_TEXT.TXT';
         tbl_cursor_value     tbl_cursor%ROWTYPE;
         col_cursor_value     col_cursor%ROWTYPE;
         v_string          varchar2(4000);
         v_string_val     varchar2(4000);
    BEGIN
         DELETE audit_triggers_status;
         COMMIT;
         --v_file_handle := utl_file.fopen(v_file_dir,v_file_name,'W',32000);
         OPEN tbl_cursor;
         LOOP
              FETCH tbl_cursor into tbl_cursor_value;
              EXIT WHEN tbl_cursor%NOTFOUND;
              OPEN col_cursor(tbl_cursor_value.table_name);
              DBMS_OUTPUT.PUT_LINE( 'CREATE OR REPLACE TRIGGER' ||' ad_'||tbl_cursor_value.table_name); -- short name for audit trigger coz table name will be appended to it and result should not exceed 30 char
              DBMS_OUTPUT.PUT_LINE( 'BEFORE INSERT OR UPDATE OR DELETE ON '||tbl_cursor_value.table_name);
              DBMS_OUTPUT.PUT_LINE( 'FOR EACH ROW');
              DBMS_OUTPUT.PUT_LINE( 'BEGIN');
              v_string:='INSERT INTO'||' ad_'||tbl_cursor_value.table_name||'(';
              v_string_val:='values(';
              INSERT INTO audit_triggers_status( table_name,trigger_name,audit_flag) VALUES (tbl_cursor_value.table_name,' ad_'||tbl_cursor_value.table_name,'Y');
                   LOOP
                        FETCH col_cursor into col_cursor_value;
                        EXIT WHEN col_cursor%NOTFOUND;
                        v_string:=v_string||col_cursor_value.column_name||',';
                        v_string_val:=v_string_val||':new.'||col_cursor_value.column_name||',';
                   END LOOP;
                   CLOSE COL_CURSOR;
              v_string:=substr(v_string,1,length(v_string)-1);
              v_string_val:=substr(v_string_val,1,length(v_string_val)-1);
              v_string:=v_string||') ';
              v_string_val:=v_string_val||');';
              --DBMS_OUTPUT.PUT_LINE(v_string||v_string_val);
              DBMS_OUTPUT.PUT_LINE('IF INSERTING THEN');
              DBMS_OUTPUT.PUT_LINE('     '||v_string||v_string_val);
              DBMS_OUTPUT.PUT_LINE('END IF;');
              DBMS_OUTPUT.PUT_LINE('IF UPDATING THEN');
              DBMS_OUTPUT.PUT_LINE('     '||v_string||v_string_val);
              DBMS_OUTPUT.PUT_LINE('END IF;');
              DBMS_OUTPUT.PUT_LINE('IF DELETING THEN');
              --DBMS_OUTPUT.PUT_LINE('     '||v_string||REPLACE(v_string_val,':new.',':old.');
              V_STRING_VAL:=REPLACE(v_string_val,':new.',':old.');
              DBMS_OUTPUT.PUT_LINE('     '||v_string||v_string_val);
              DBMS_OUTPUT.PUT_LINE('END IF;');
              DBMS_OUTPUT.PUT_LINE('END '||' ad_'||tbl_cursor_value.table_name||';');
              DBMS_OUTPUT.PUT_LINE(' ');
         END LOOP;
         CLOSE TBL_CURSOR;
         COMMIT;
    END;

  • How to get table and column names thats being used in SQL , that's generating all my reports on SSRS.

    Good day,
    I searched through the forum and cant find anything.
    I have around 300 published reports on SSRS and we are busy migrating to a new system.
    They have already setup their tables on the new system and I need to provide them with a list of table names and column names that are being used currently to generate the 300 reports on SSRS.
    We use various tables and databases to generate these reports, and will take me forever to go through each query to get this info.
    Is it at all possible to write a query in SQL 2008 that will give me all the table names and columns being used?
    Your assistance is greatly appreciated.
    I thank you.
    Andre.

    There's no straightforward method for that I guess. There are couple of things you can use to get these details
    1. query the ReportServer.dbo.Catalog table
    for getting details
    you may use script below for that
    http://gallery.technet.microsoft.com/scriptcenter/42440a6b-c5b1-4acc-9632-d608d1c40a5c
    2. Another method is to run the reports and run sql profiler trace on background to retrieve queries used.
    But in some of these cases the report might be using a procedure and you will get only procedure. Then its upto you to get the other details from procedure like tables used, columns etc
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Check the table and column name in R12 web screen

    Hello Friends
    Please any body can tell me how can I find out the table name and column name in web based forms like supplier, customer in R12. In 11i I can find out the table name and column name from help menu by record history and diagnostic -> examine menu.
    Thansk
    Makshud

    Hi,
    Please see (Note: 741366.1 - How to get Supplier table information? How to get About this Page link in OA page in R12).
    Thanks,
    Hussein

  • Query to Find Table and Column Name by using a value

    Dear Legends,
    I hope and surfed in our forums and google to find the Table Name and Column Name by having a value(Number/String). And my where clauses are
    where owner NOT IN ('SYS','SYSTEM') and
          data_type IN ('CHAR','VARCHAR2','NUMBER')
    May I have your help for building the query. and my query as follows
    select a.owner, c.column_name, c.data_type, c.owner, c.table_name
    from dba_objects a, all_tab_cols c
    where a.owner NOT IN ('SYS','SYSTEM') and
    where c.owner NOT IN ('SYS','SYSTEM') and
    where c.data_type IN ('CHAR','VARCHAR2')
    order by a.owner
    Thanks,
    Karthik

    You can use
    select * from user_tab_columns a, user_tables b
    where a.table_name = b.table_name
    and  a.data_type in ('NUMBER', 'VARCHAR2', 'NCHAR', 'CHAR');
    Or if you want to user DBA_* tables, you can use.
    select * from dba_tab_columns a, dba_tables b
    where a.table_name = b.table_name
    and a.owner = b.owner
    and  a.data_type in ('NUMBER', 'VARCHAR2', 'NCHAR', 'CHAR')
    and b.owner not in ('SYS', 'SYSTEM');
    And now when I look a bit more closely, you don't need DBA_TABLES there. dba_tab_columns alone is sufficient. And requirement is still not clear yet. Why you need a group by there? If I get it right, you can use this.
    select * from dba_tab_columns a
    where a.data_type in ('NUMBER', 'VARCHAR2', 'NCHAR', 'CHAR')
    and a.owner not in ('SYS', 'SYSTEM');
    Whether you use group by or not, the query will give you the same output.
    Ishan

  • Deleting from multiple tables where few tables have same column name

    Hi,
    I am new to PL/SQL and need some help. I need to delete data older then X years from some 35 odd tables in my schema and out of those tables 25 tables have same column name on which i can have my "where" clause and rest 10 table have different table names. I am doing something like this :
    declare
    table_list UTL_FILE.FILE_TYPE;
    string_line VARCHAR2(1000);
    tables_count number:=0;
    table_name VARCHAR2(400);
    column_name VARCHAR2(400);
    BEGIN
    table_list := UTL_FILE.FOPEN('ORALOAD','test7.txt','R');
    DBMS_OUTPUT.PUT_LINE(table_list);
    LOOP
    UTL_FILE.GET_LINE(table_list,string_line);
    table_name := substr(string_line,1, instr(string_line,'|')-1);
    column_name := substr(string_line, instr(string_line,'|')+1);
    DBMS_OUTPUT.PUT_LINE(table_name);
    DBMS_OUTPUT.PUT_LINE(column_name);
    IF column_name = 'SUBMISSION_TIME' THEN
    delete from :table_name where to_date(:column_name)<(sysdate-(365*7));
    ELSE
    delete from || table_name || where ( || to_date(column_name) || ) <(sysdate-(365*7));
    END IF;
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    UTL_FILE.FCLOSE(table_list);
    DBMS_OUTPUT.PUT_LINE('Number of Tables processed is : ' || tables_count);
    UTL_FILE.FCLOSE(table_list);
    END;
    WHERE the text file "text7.txt" contains list of table name and column names separated by a pipe line. But when I execute the above proc it gives error "invalid table name".
    Can something like this be done or is there any other way to execute this task of deletion from 35 tables.
    Thanks.

    Thanks for replies. I don't know what I am doing wrong but still not getting this damn thing work...This is the proc i am running now :
    declare
    table_list UTL_FILE.FILE_TYPE;
    string_line VARCHAR2(1000);
    tables_count number:=0;
    table_name VARCHAR2(4000);
    column_name VARCHAR2(4000);
    code_text VARCHAR2(2000);
    BEGIN
    table_list := UTL_FILE.FOPEN('ORALOAD','test7.txt','R');
    LOOP
    UTL_FILE.GET_LINE(table_list,string_line);
    table_name := substr(string_line,1, instr(string_line,'|')-1);
    column_name := substr(string_line, instr(string_line,'|')+1);
    IF column_name = 'SUBMISSION_TIME' THEN
    DBMS_OUTPUT.PUT_LINE('do nothing');
    ELSE
    code_text:= 'begin delete from'|| (table_name) ||'where to_date' || (column_name) || '<(sysdate-(365*7))';
    Execute Immediate code_text;
    END IF;
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    UTL_FILE.FCLOSE(table_list);
    DBMS_OUTPUT.PUT_LINE('Number of Tables processed is : ' || tables_count);
    UTL_FILE.FCLOSE(table_list);
    END;
    But it gives following error :
    " ORA-06550: line 1, column 51:
    PL/SQL: ORA-00933: SQL command not properly ended
    ORA-06550: line 1, column 7:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 1, column 68:
    PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
    ORA-06512: at line 22 "

  • Special Characters and spaces in Tablenames and Column Names are allowed ?

    Hi
    I have created two tables in Oracle10g
    as follows
    SQL> create table test(columna number,columnb varchar2(20),primary key(columna));
    Table created.
    SQL> insert into test values(1,'test');
    1 row created.
    SQL> commit;
    COMMIT är utfört.
    SQL> create table "test quote"("#" number,abc number,primary key("#"));
    Table created.
    SQL> insert into "test quote" values(1,2);
    1 row created.
    SQL> commit;
    COMMIT är utfört.
    SQL> select * from "test quote";
    # ABC
    1 2
    SQL> select * from test;
    COLUMNA COLUMNB
    1 test
    Now I want to cache the tables and their data into TimesTen
    The cache group for table test which is not having any spaces and special characters in table name and column names is created perfectly.
    But when I create the cache group for table "test quote" which is having special characters and spaces it gives error :
    Command>create readonly cache group w2 from testuser.test(columna number,columnb varchar2(20),primary key(columna));
    Command>select * from test;
    <1,test>
    1 row found.
    Command>create readonly cache group w3 from testuser."test quote"("#" number,abc number,primary key("#"));
    5140: Could not find TESTUSER.TEST QUOTE in Oracle. May not have privileges.
    Command Failed.
    Now there is contradiction that why cache group for table test is created successfully and why it is not being created for table "test quote".
    What I think is if special characters and spaces in column names and table names are possible in Oracle then it sould be possible in TimesTen.
    Any possible solution.
    Looking forward for your reply.
    Please help I am stuck badly.
    /Ahmad

    Hi
    Problem Solved ....... Remeber only Capital letters work with special characters ......
    /Ahmad

Maybe you are looking for

  • Wdr:select_options and highlight Error Message with a Link to Inputfield

    Hi, I have created a InputField on a View using WDR_SELECT_OPTIONS. I want to validate this Input Field and give Error Message, when User fill it with wrong Values. How can we achieve this and important is to mark it on Screen WITH a RED STAR. ( e.g.

  • OC4J 9.0.3 ClassCastException instability

    Hi, I´m trying to use OC4J 9.0.3 StandAlone, I packaged the app on a EAR and deploied them using JDeveloper 9.0.3. The deploy was fine and the app runs nicely for about 3 or 5 hours but then the OC4J throws ClassCastException when I try to access one

  • LV7 finite pulse train on digital line.

    I was wondering how I would go about creating a digital pulse train on a digital out line. I saw some example that LV7 came with but they were not too clear on what was going on, and also it involed the couter, which in my case I dont really need, Im

  • How do I program controls for my robot?

    Currently I'm trying to Program a robot to move according to the control of a person using a controller. I am having trouble getting the robot to response to the controller is there any tutorials or help threads out there I can use to help fix my pro

  • Remove "Page" Link in SharePoint Modal Popup

     Hi,.  How to remove "Page" Link in SharePoint Modal Popup as shown below Ravindranath