Oracle

creating a pandas dataframe from a database query that uses bind variables

大憨熊 提交于 2021-02-07 03:29:01
问题 I'm working with an Oracle database. I can do this much: import pandas as pd import pandas.io.sql as psql import cx_Oracle as odb conn = odb.connect(_user +'/'+ _pass +'@'+ _dbenv) sqlStr = "SELECT * FROM customers" df = psql.frame_query(sqlStr, conn) But I don't know how to handle bind variables, like so: sqlStr = """SELECT * FROM customers WHERE id BETWEEN :v1 AND :v2 """ I've tried these variations: params = (1234, 5678) params2 = {"v1":1234, "v2":5678} df = psql.frame_query((sqlStr,params

How to check if a database link is valid in Oracle?

点点圈 提交于 2021-02-07 03:29:00
问题 I have a main database with only setup data at the headquarter and several databases at different branches.I created a database link for each branch server. In some case I would like to query all the valid links (as some links could be invalid due to connection problems or anything else),so my question is How to check if the database link is valid without getting in Connection timeout problems. Is there a SQL statement to let the oracle main server do that check and return only the valid

How to check if a database link is valid in Oracle?

a 夏天 提交于 2021-02-07 03:26:31
问题 I have a main database with only setup data at the headquarter and several databases at different branches.I created a database link for each branch server. In some case I would like to query all the valid links (as some links could be invalid due to connection problems or anything else),so my question is How to check if the database link is valid without getting in Connection timeout problems. Is there a SQL statement to let the oracle main server do that check and return only the valid

how to get names of partition in oracle while i input a date

本小妞迷上赌 提交于 2021-02-07 03:22:27
问题 I have a table with many partitions range. I need to get the name of all partition when I give a date. For eg: if I input date 20/09/2014, it should list all partitions before that given date. create or replace function get_part_name(p_date in date) return varchar2 is d date; retp varchar2(30); mind date:=to_date('4444-01-01','yyyy-mm-dd'); str varchar2(32000); cursor c is select high_value, partition_name p from user_tab_partitions where table_name='TEST'; begin for r in c loop str := r.high

how to get names of partition in oracle while i input a date

£可爱£侵袭症+ 提交于 2021-02-07 03:20:28
问题 I have a table with many partitions range. I need to get the name of all partition when I give a date. For eg: if I input date 20/09/2014, it should list all partitions before that given date. create or replace function get_part_name(p_date in date) return varchar2 is d date; retp varchar2(30); mind date:=to_date('4444-01-01','yyyy-mm-dd'); str varchar2(32000); cursor c is select high_value, partition_name p from user_tab_partitions where table_name='TEST'; begin for r in c loop str := r.high

How to find parameters in Oracle query received from v$sql?

拥有回忆 提交于 2021-02-06 15:25:28
问题 I use query: select LAST_LOAD_TIME, ELAPSED_TIME, MODULE, SQL_TEXT elasped from v$sql WHERE MODULE='JDBC Thin Client' ORDER BY LAST_LOAD_TIME DESC elasped: delete from tableA where fk in (select pk from tableB where tableB.fk=:1 and tableB.date between :2 and :3) Is it possible find these parameters 1, 2 and 3? 回答1: Something like this: select s.sql_id, bc.position, bc.value_string, s.last_load_time, bc.last_captured from v$sql s left join v$sql_bind_capture bc on bc.sql_id = s.sql_id and bc

SQL Query to return N rows from dual

五迷三道 提交于 2021-02-06 15:24:06
问题 I want to write a SQL query which accepts a bind variable (say :NUM) and its output consists of one column & :NUM number of rows, each row having its row number. i.e. if we pass :NUM as 7, the output should be: VAL ==== 1 2 3 4 5 6 7 There shouldn't be any actual DB tables in query and no PL/SQL code should be used. i.e. only dual should be used in the query Is there any way to achieve this? 回答1: You could use: WHERE ROWNUM <= :NUM ...but the table has to contain row equal or greater to the

SQL Query to return N rows from dual

跟風遠走 提交于 2021-02-06 15:23:15
问题 I want to write a SQL query which accepts a bind variable (say :NUM) and its output consists of one column & :NUM number of rows, each row having its row number. i.e. if we pass :NUM as 7, the output should be: VAL ==== 1 2 3 4 5 6 7 There shouldn't be any actual DB tables in query and no PL/SQL code should be used. i.e. only dual should be used in the query Is there any way to achieve this? 回答1: You could use: WHERE ROWNUM <= :NUM ...but the table has to contain row equal or greater to the

SQL Query to return N rows from dual

眉间皱痕 提交于 2021-02-06 15:23:05
问题 I want to write a SQL query which accepts a bind variable (say :NUM) and its output consists of one column & :NUM number of rows, each row having its row number. i.e. if we pass :NUM as 7, the output should be: VAL ==== 1 2 3 4 5 6 7 There shouldn't be any actual DB tables in query and no PL/SQL code should be used. i.e. only dual should be used in the query Is there any way to achieve this? 回答1: You could use: WHERE ROWNUM <= :NUM ...but the table has to contain row equal or greater to the

How to find parameters in Oracle query received from v$sql?

假装没事ソ 提交于 2021-02-06 15:22:55
问题 I use query: select LAST_LOAD_TIME, ELAPSED_TIME, MODULE, SQL_TEXT elasped from v$sql WHERE MODULE='JDBC Thin Client' ORDER BY LAST_LOAD_TIME DESC elasped: delete from tableA where fk in (select pk from tableB where tableB.fk=:1 and tableB.date between :2 and :3) Is it possible find these parameters 1, 2 and 3? 回答1: Something like this: select s.sql_id, bc.position, bc.value_string, s.last_load_time, bc.last_captured from v$sql s left join v$sql_bind_capture bc on bc.sql_id = s.sql_id and bc